[Mono-osx] MonoMac bindings trouble
Raymond Reggers
raymond at adaptiv.nl
Tue Feb 14 22:20:56 UTC 2012
Ok I created the bindings by running this command on the file below:
mono bmac.exe ${ProjectDir}/Bindings/Vespertilio.Presentation.cs -r System.Drawing
using MonoMac.Foundation;
using MonoMac.AppKit;
namespace Vespertilio.Presentation {
[BaseType(typeof(NSView))]
interface TextView
{
}
}
And dlopen() is called before anything else, first line in Main(). The library gets loaded because I can see my custom view being displayed.
For example, I can do this (MainWindowController.cs):
public override void WindowDidLoad ()
{
base.WindowDidLoad();
Vespertilio.Presentation.TextView t = new Vespertilio.Presentation.TextView();
this.root.AddSubView(t);
t.setFrame(...
}
In this case root is simply a NSView with an outlet to MainWindowController.root.
BUT if I use interfacebuilder (well XCode now) and replace NSView with TextView and bind an outlet to MainWindowController.root. Then I get an InvalidCastException. If I remove the outlet, everything works and my custom view also shows.
Hope this helps.
Thanks!
On Feb 14, 2012, at 8:26 PM, Duane Wandless wrote:
> It might help if you show your bindings... and when did you call dlopen on the framework?
>
> dlopen(...
> NSApplication.Init()
> NSApplication.Main()
>
> On Mon, Feb 13, 2012 at 9:14 PM, Raymond Reggers <raymond at adaptiv.nl> wrote:
> 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
> _______________________________________________
> Mono-osx mailing list
> Mono-osx at lists.ximian.com
> http://lists.ximian.com/mailman/listinfo/mono-osx
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.ximian.com/pipermail/mono-osx/attachments/20120214/2abc100f/attachment.html>
More information about the Mono-osx
mailing list