I'm porting a .NET-based test automation framework to Mac OS X. I have significant .NET experience, however, I'm totally a rookie in the Mac world.
I need to call Objective C code from .NET / Mono. I started with the "MonoMac - Binding Objective-C Types" tutorial.
I created an API definition file. I couldn't compile it, because the type "BaseTypeAttribute" couldn't be found. Later I found that this is not a problem, because the btouch tool will compile it (basetypeattribute-not-found-in-a-binding-project).
Since I'm developing for OS X (not iOS), I was not using btouch, I was going to use the bmac tool. Findig that wasn't trivial, but I managed to compile&found it based on this article. Good.
I was not able to compile my binding file, because the bmac said "Type or namespace 'Tasks' does not exists in namespace 'System.Threading'". Nevertheless, I specified an output folder for the generated .cs files, fixed the compile error (the Tasks wasn't really needed, the error was caused by an unnecessary using that was generated).
So I'm about at the point where I could have been if I followed the manual "Binding New Objective-C Types / Binding_Details" document.
The problem is that I still cannot use my Objective C library. I can compile and run the C# code with MonoDevelop/Xamarin, but it fails with the message:
System.Exception: Could not create an native instance of the type 'My.Type': the native class hasn't been loaded.
It is possible to ignore this condition by setting MonoMac.ObjCRuntime.Class.ThrowOnInitFailure to false.
at MonoMac.Foundation.NSObject.InitializeObject (Boolean alloced)
at MonoMac.Foundation.NSObject..ctor (MonoMac.Foundation.NSObjectFlag x)
at My.Type..ctor ()
I found an article (coreplot-monomac-bindings-crashing) that says the library must be manually loaded before using it, but I had no luck with it. "Dlfcn.dlopen" always return IntPtr.Zero.
- I'm tried to create my lib as "Cocoa Framework", "Cocoa Library" and "Bundle" in XCode. Which one should I use?
- Are there any low-level debugging possibilites in Mono(Mac)?
- Did anybody managed to do this? (calling objc from .net)
thanks in advance, -g