Type registrar and dynamically (at runtime) loaded libraries

FelixDeimelFelixDeimel ATMember ✭✭

Hi there,

I'm still trying to get a basic plugin system set up in Xamarin.Mac.
Basically I want to be able to load a bundle containing a compiled mono library and additional assets like views, windows, images, etc. at runtime.

The basics are working. I create my .framework bundle as part of a post-build script, copy over any resources I need and am able to dynamically load that bundle at runtime, instantiate classes that are contained within it and load Cocoa windows and views. So far so good.

However, I'm now having an issue with the type registrar not surfacing some of my classes to the Objective-C runtime. The classes that don't get registered with the Objective-C runtime are not instantiated by my code but through xib's. For example, I have a xib with a window for which I set the subclass to one of the classes in the dynamically loaded dll.

When running the application I see Unknown Window class DragBackgroundWindow in Interface Builder file, creating generic Window instead in the output window and if I try this code IntPtr classHandle = ObjCRuntime.Class.GetHandle("DragBackgroundWindow");, the classHandle is a zero pointer.

Now if I instantiate this class once before the xib actually loads, I have non of these issues which leads me to believe that this forces the runtime to register the class with the Objective-C runtime. That's not really a good workaround however as it obviously creates unnecessary garbage/dummy objects and isn't very intuitive either.

So the question boils down to: How on earth can I let the Xamarin.Mac runtime know that I want it to register all subclasses of Cocoa types to the Objective-C runtime upon loading a dll?

Here's my current work in progress sample: https://github.com/lemonmojo/xamarin-mac-plugin-test
Changing if (false) { to if (true) { in line 37 of UIStuffMainClass.cs of the UIStuff project works around the problem but isn't the solution I'm looking for.

thx,
felix

Best Answer

Answers

  • FelixDeimelFelixDeimel ATMember ✭✭

    Perfect! That did it!

    Many thx,
    felix

Sign In or Register to comment.