I'm seeing this crash consistently at the moment. I've seen it occur from a few different types of objects. From searches, this seems to be related to objects being GC'd and then referenced. Not sure what I'm doing to bring on the issue and I've seen one reference to this being a bug in the GC itself.
In my case I started with a single view application and then removed the additional controllers to get down to a single rootviewcontroller.cs. I'm accessing this.Window.RootViewController in FinishedLaunching. I do the same in a Swift app with no issue -- I'm in the middle of making a port from a Swift app into a Xamarin equivalent app.
C#
public override bool FinishedLaunching (UIApplication application, NSDictionary launchOptions)
{
// Override point for customization after application launch.
beaconManager = new BeaconManager (this.Window.RootViewController as BeaconView);
return true;
}
Swift
func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: NSDictionary?) -> Bool {
self.ibeaconManager = iBeaconManager(beaconView: self.window?.rootViewController as BeaconView)
return true
}
System.Exception: Failed to marshal the Objective-C object 0x15e54790 (type: RootViewController). Could not find an existing managed instance for this object, nor was it possible to create a new managed instance (because the type 'ProximlyXamarin.RootViewController' does not have a constructor that takes one IntPtr argument).
at MonoTouch.ObjCRuntime.Runtime.MissingCtor (IntPtr ptr, IntPtr klass, System.Type type, MissingCtorResolution resolution) [0x00046] in /Developer/MonoTouch/Source/monotouch/src/ObjCRuntime/.pmcs-compat.Runtime.cs:400
at MonoTouch.ObjCRuntime.Runtime.ConstructNSObject[UIViewController] (IntPtr ptr, System.Type type, MissingCtorResolution missingCtorResolution) [0x00000] in :0
at MonoTouch.ObjCRuntime.Runtime.GetNSObject[UIViewController] (IntPtr ptr) [0x00000] in :0
at MonoTouch.UIKit.UIWindow.get_RootViewController () [0x00008] in /Developer/MonoTouch/Source/monotouch/src/build/compat/UIKit/.pmcs-compat.UIWindow.g.cs:282
at ProximlyXamarin.AppDelegate.FinishedLaunching (MonoTouch.UIKit.UIApplication application, MonoTouch.Foundation.NSDictionary launchOptions) [0x00008] in /Users/jay/Projects/ProximlyXamarin/ProximlyXamarin/AppDelegate.cs:27
at at (wrapper managed-to-native) MonoTouch.UIKit.UIApplication:UIApplicationMain (int,string[],intptr,intptr)
at MonoTouch.UIKit.UIApplication.Main (System.String[] args, System.String principalClassName, System.String delegateClassName) [0x0004c] in /Developer/MonoTouch/Source/monotouch/src/UIKit/.pmcs-compat.UIApplication.cs:38
at ProximlyXamarin.Application.Main (System.String[] args) [0x00008] in /Users/jay/Projects/ProximlyXamarin/ProximlyXamarin/Main.cs:17