[Mono-osx] MonoMac bindings trouble

Raymond Reggers raymond at adaptiv.nl
Tue Feb 14 02:14:34 UTC 2012


Hi all,

Got another question regarding bindings to my own obj-c classes, my situation and problem is like this:

- I got an obj-c class named TextView which extends NSView, that I compiled into a Cocoa Framework.
- Loaded this Framework with Dlcfn.dlopen 
- Created the bindings using bmac.

Now from c# I can create an instance from my TextView class, add it to an existing view. Works fine. 

But it seems my bindings do not work in a reverse manner. For example if I:

- Add my TextView to MainWindow.xib using XCode. 
- Create an outlet to MainWindowController.

When launching the application, the TextView shows up correctly, but upon resolving the outlet I get a InvalidCastException (stacktrace below). So I tried something else:

- Add my TextView into a NSView
- Create an outlet for the NSView (named it root)
- Access MainWindowController.root.Subviews[0]

In the debugger this shows up as a NSView. And casting to TextView results in the same InvalidCastException. I must be doing something wrong with my bindings? Hope someone can help.

Kind regards,

Raymond

Stacktrace:

at (wrapper managed-to-native) object.__icall_wrapper_mono_object_castclass (object,intptr) <0x00003>
at MonoMac.ObjCRuntime.NSObjectMarshaler`1<Vespertilio.Presentation.TextView>.MarshalNativeToManaged (intptr) <0x0004b>
at (wrapper native-to-managed) object.[Vespertilio.Mac.MainWindowController.Void set_root(Vespertilio.Presentation.TextView)] (MonoMac.Foundation.NSObject,MonoMac.ObjCRuntime.Selector,Vespertilio.Presentation.TextView) <IL 0x0004a, 0x001a0>
at (wrapper managed-to-native) MonoMac.ObjCRuntime.Messaging.IntPtr_objc_msgSendSuper (intptr,intptr) <0x00003>
at MonoMac.AppKit.NSWindowController.get_Window () [0x0002b] in /Users/raymond/Documents/git/monomac/src/AppKit/NSWindowController.g.cs:371
at Vespertilio.Mac.MainWindowController.get_Window () [0x00000] in /Volumes/DATA/vespertilio/Vespertilio/Vespertilio.Mac/MainWindowController.cs:49
at Vespertilio.Mac.AppDelegate.FinishedLaunching (MonoMac.Foundation.NSObject) [0x0000b] in /Volumes/DATA/vespertilio/Vespertilio/Vespertilio.Mac/AppDelegate.cs:20
at (wrapper dynamic-method) object.[Vespertilio.Mac.AppDelegate.Void FinishedLaunching(MonoMac.Foundation.NSObject)] (MonoMac.Foundation.NSObject,MonoMac.ObjCRuntime.Selector,MonoMac.Foundation.NSObject) <IL 0x00011, 0x00050>
at (wrapper native-to-managed) object.[Vespertilio.Mac.AppDelegate.Void FinishedLaunching(MonoMac.Foundation.NSObject)] (MonoMac.Foundation.NSObject,MonoMac.ObjCRuntime.Selector,MonoMac.Foundation.NSObject) <IL 0x0006a, 0x001fb>
at (wrapper managed-to-native) MonoMac.AppKit.NSApplication.NSApplicationMain (int,string[]) <0x00003>
at MonoMac.AppKit.NSApplication.Main (string[]) [0x00000] in /Users/raymond/Documents/git/monomac/src/AppKit/NSApplication.cs:74
at Vespertilio.Mac.MainClass.Main (string[]) [0x0000f] in /Volumes/DATA/vespertilio/Vespertilio/Vespertilio.Mac/Main.cs:21


More information about the Mono-osx mailing list