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.
1. Run the DrawerMadness sample
2. Click the "Open" button in the top-left
The app will fault with:
System.InvalidCastException: Cannot cast from source type to destination type.
at (wrapper managed-to-native) object:__icall_wrapper_mono_object_castclass (object,intptr)
at MonoMac.ObjCRuntime.NSObjectMarshaler`1[MonoMac.AppKit.NSButtonCell].MarshalNativeToManaged (IntPtr handle) [0x00021] in /mono/monomac/src/ObjCRuntime/NSObjectMarshaler.cs:35
at (wrapper native-to-managed) object:[DrawerMadness.ParentWindowController:Void openLeftDrawer(MonoMac.AppKit.NSButtonCell)] (MonoMac.Foundation.NSObject,MonoMac.ObjCRuntime.Selector,MonoMac.AppKit.NSButtonCell)
at (wrapper managed-to-native) MonoMac.AppKit.NSApplication:NSApplicationMain (int,string)
at MonoMac.AppKit.NSApplication.Main (System.String args) [0x0000a] in /mono/monomac/src/AppKit/NSApplication.cs:77
at DrawerMadness.MainClass.Main (System.String args) [0x00005] in /monomac/samples/DrawerMadness/DrawerMadness/Main.cs:18
The problem is that Cocoa is passing an NSMatrix from the XIB as the sender but the tool that auto-generated the designer file output a method with an NSButtonCell sender instead. Looking at the original native sources to the sample, the messages just take an "id" as sender, so nothing more than an NSObject is required in this case.
The sample can be fixed by changing the protocol implementation to accept either NSMatrix or NSObject, but the tool that generated the designer file from the XIB needs to be fixed to generate this.
This sample is working correctly now.