Notice (2018-05-24): bugzilla.xamarin.com is now in
Please join us on
Visual Studio Developer Community and in the
Mono organizations on
GitHub to continue tracking issues. Bugzilla will remain
available for reference in read-only mode. We will continue to work
on open Bugzilla bugs, copy them to the new locations
as needed for follow-up, and add the new items under Related
Our sincere thanks to everyone who has contributed on this bug
tracker over the years. Thanks also for your understanding as we
make these adjustments and improvements for the future.
Please create a new report on
Developer Community or GitHub with
your current version information, steps to reproduce, and relevant error
messages or log files if you are hitting an issue that looks similar to
this resolved bug and you do not yet see a matching new report.
When .NET backed UIKit elements are GC'ed by the Mono GC, on a device, the following error appears :
015-03-06 10:40:53.031 PjciOS[1010:258598] System.Exception: Failed to marshal the Objective-C object 0x1ac7d5d0 (type: App1.MyControl).
Could not find an existing managed instance for this object, nor was it possible to create a new managed instance (because the type 'App1.MyControl' does not have a constructor that takes one IntPtr argument).
Method: App1.MyControl:WillRemoveSubview (UIKit.UIView)
at (wrapper managed-to-native) Foundation.NSObject:xamarin_release_managed_ref (intptr,intptr)
at Foundation.NSObject.ReleaseManagedRef () [0x00000] in /Developer/MonoTouch/Source/maccore/src/Foundation/NSObject2.cs:198
at Foundation.NSObject+NSObject_Disposer.Drain (Foundation.NSObject ctx) [0x00062] in /Developer/MonoTouch/Source/maccore/src/Foundation/NSObject2.cs:805
at (wrapper managed-to-native) UIKit.UIApplication:UIApplicationMain (int,string,int
In the simulator, this dose not crash the application, and just displays an warning message.
In this case, the control in question is not available anymore, and it is acceptable to ignore this error, and we do not want to have a IntPtr constructor.
This is not that easy to ignore, and in general indicates that something is wrong in the app.
Can you attach your project so that we can reproduce your particular case ourselves and see if it's something can fix?
Created attachment 10804 [details]
The repro I added demonstrates that when running in the simulator, the app will not crash, while showing this message :
2015-04-17 10:46:17.503 App5[19997:11365764] warning: Ignoring invocation of an instance method on a NULL instance.
But on an actual device, it will crash in the drain.
We need to be able to write this kind of sequence for memory management, where it is required to dispose objects for proper all sorts of things, like event handlers, etc...
Isn't the wrapper supposed to remove the code handling C# provided overrides, even when it is disposed via the finalizer ?
This has been fixed in Xamarin.iOS 8.10, the sample runs fine on both device and simulator.