P/Invoke into .framework files on Mono Mac

747 Views Asked by At

I am porting some C# code we had on Windows to be used on the Mac via Mono. In our code we P\Invoke into a unmanaged C++ dll. Unfortunately the build process we have can only give out a Framework file on the Mac and not a dylib file.

When I ported my code for Mono everything works fine but the P\Invoke into the Framework file. I tried adding out framework file to /Library/Frameworks folder which should be in the default search path but I keep getting a DllNotFound exception. According to the Mono Interop Guide there is an issue with Mono adding .so as the extension to search for on the Mac. So I tried adding a config file and give the target as a .framework file but still I got the same exception. The Mono guide mentions it gets more complicated to do a P\Invoke with Frameworks but doesn't mention the exact issues or how to get around them.

Anybody Know how to P\Invoke into a Framework on Mono?

1

There are 1 best solutions below

0
On

You can put your framework inside the generated app bundle, see my answer to this question: Setting path of the Native Library for DllImport on Mono for Mac

Also make sure to set the framework's installation directory relative to your application directory (ie. @executable_path/../Frameworks) in XCode's build configuration; see https://developer.apple.com/library/mac/#documentation/MacOSX/Conceptual/BPFrameworks/Tasks/CreatingFrameworks.html.

This is especially important when bundling more than one framework - for instance, if if you P/Invoke into some method in A.framework which depends on B.framework.