Bug 8581 - Parameter marshaling fails in DrawerMadness sample due to designer generation error
Summary: Parameter marshaling fails in DrawerMadness sample due to designer generation...
Status: RESOLVED FIXED
Alias: None
Product: MonoMac
Classification: Desktop
Component: Bindings ()
Version: GIT
Hardware: Macintosh Mac OS
: --- normal
Target Milestone: ---
Assignee: Bugzilla
URL:
Depends on:
Blocks:
 
Reported: 2012-11-23 19:23 UTC by Aaron Oneal
Modified: 2015-02-18 11:27 UTC (History)
3 users (show)

Tags:
Is this bug a regression?: ---
Last known good build:

Notice (2018-05-24): bugzilla.xamarin.com is now in read-only mode.

Please join us on Visual Studio Developer Community and in the Xamarin and 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 Links.

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.

Related Links:
Status:
RESOLVED FIXED

Description Aaron Oneal 2012-11-23 19:23:01 UTC
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.
Comment 1 Timothy Risi 2015-02-18 11:27:25 UTC
This sample is working correctly now.