How to properly map a DLL name to a native Mac framework

jlaasejlaase USMember
edited November 2017 in Xamarin.iOS

I am trying to use the Chromium Embedded Framework.framework in my Mac app. In my sample .net code, this framework is referenced as libcef.dll. When I call a method on the framework, I get a System.DllNotFound exception. I have looked at DLL maps to map the CEF framework to the expected DLL name and I have the following map but this did not resolve the issue.

<configuration>
       <dllmap dll="libcef" target="/Library/Frameworks/Chromium\ Embedded\ Framework.framework/Chromium Embedded Framework" />
</configuration>

I have also added the framework to my project as a native reference but nor did this resolve the issue.

Does anyone know how I might be able to get around this DllNotFound exception?

The stack trace is this.

System.DllNotFoundException: libcef
at at (wrapper managed-to-native) Xilium.CefGlue.Interop.libcef:api_hash (int)
at Xilium.CefGlue.CefRuntime.CheckVersionByApiHash () [0x00002] in /Users/jlaase/Documents/dev/xilium.cefglue/CefGlue/CefRuntime.cs:106
at Xilium.CefGlue.CefRuntime.CheckVersion () [0x00002] in /Users/jlaase/Documents/dev/xilium.cefglue/CefGlue/CefRuntime.cs:92
at Xilium.CefGlue.CefRuntime.Load () [0x0000c] in /Users/jlaase/Documents/dev/xilium.cefglue/CefGlue/CefRuntime.cs:81
at System.Threading.Tasks.Task.InnerInvoke () [0x0000f] in /Users/builder/data/lanes/4992/mono-mac-sdk/external/bockbuild/builds/mono-x64/mcs/class/referencesource/mscorlib/system/threading/Tasks/Task.cs:2879
at System.Threading.Tasks.Task.Execute () [0x00010] in /Users/builder/data/lanes/4992/mono-mac-sdk/external/bockbuild/builds/mono-x64/mcs/class/referencesource/mscorlib/system/threading/Tasks/Task.cs:2502
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw () [0x0000c] in /Users/builder/data/lanes/4992/mono-mac-sdk/external/bockbuild/builds/mono-x64/mcs/class/referencesource/mscorlib/system/runtime/exceptionservices/exceptionservicescommon.cs:152
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess (System.Threading.Tasks.Task task) [0x00037] in /Users/builder/data/lanes/4992/mono-mac-sdk/external/bockbuild/builds/mono-x64/mcs/class/referencesource/mscorlib/system/runtime/compilerservices/TaskAwaiter.cs:187
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification (System.Threading.Tasks.Task task) [0x00028] in /Users/builder/data/lanes/4992/mono-mac-sdk/external/bockbuild/builds/mono-x64/mcs/class/referencesource/mscorlib/system/runtime/compilerservices/TaskAwaiter.cs:156
at System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd (System.Threading.Tasks.Task task) [0x00008] in /Users/builder/data/lanes/4992/mono-mac-sdk/external/bockbuild/builds/mono-x64/mcs/class/referencesource/mscorlib/system/runtime/compilerservices/TaskAwaiter.cs:128
at System.Runtime.CompilerServices.TaskAwaiter.GetResult () [0x00000] in /Users/builder/data/lanes/4992/mono-mac-sdk/external/bockbuild/builds/mono-x64/mcs/class/referencesource/mscorlib/system/runtime/compilerservices/TaskAwaiter.cs:113
at Demo.CefGlue.AppDelegate+c__async0.MoveNext () [0x00099] in <6839508fd4284d13b86c5e47bd563ec6>:0
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw () [0x0000c] in /Users/builder/data/lanes/4992/mono-mac-sdk/external/bockbuild/builds/mono-x64/mcs/class/referencesource/mscorlib/system/runtime/exceptionservices/exceptionservicescommon.cs:152
at System.Runtime.CompilerServices.AsyncMethodBuilderCore+<>c.b__6_0 (System.Object state) [0x00000] in /Users/builder/data/lanes/4992/mono-mac-sdk/external/bockbuild/builds/mono-x64/mcs/class/referencesource/mscorlib/system/runtime/compilerservices/AsyncMethodBuilder.cs:1018
at MonoMac.AppKit.AppKitSynchronizationContext+c__AnonStorey0.<>m__0 () [0x00000] in <69849e6b886848f68ef0f56b62fe76aa>:0
at MonoMac.Foundation.NSAsyncActionDispatcher.Apply () [0x00002] in <69849e6b886848f68ef0f56b62fe76aa>:0
at at (wrapper managed-to-native) MonoMac.AppKit.NSApplication:NSApplicationMain (int,string[])
at MonoMac.AppKit.NSApplication.Main (System.String[] args) [0x0003d] in <69849e6b886848f68ef0f56b62fe76aa>:0
at Demo.CefGlue.MainClass.Main (System.String[] args) [0x00006] in <6839508fd4284d13b86c5e47bd563ec6>:0

Thanks,

Josh

Answers

  • jlaasejlaase USMember

    It seems that my DLL map got stripped from the post. Here is the map that I am using.

    <configuration>
      <dllmap dll="libcef.dll" target=" /Library/Frameworks/Chromium Embedded Framework/Chromium Embedded Framework"/>
    </configuration>
    
  • ChrisHamonsChrisHamons USForum Administrator, Xamarin Team Xamurai

    I'm not sure off the top of my head, but one useful tip in debugging items of this nature is to use MONO_LOG_LEVEL and MONO_LOG_MASK. Those print out internal mono info on how/why it resolved or rejected certain libraries.

    I'd try something like:

    MONO_LOG_LEVEL=debug MONO_LOG_MASK=dll ./Foo.app/Contents/MacOS/Foo

  • jlaasejlaase USMember

    Chris, thank you for the response. Is there a way to set the MONO_LOG_LEVEL from within Visual Studio and get the logs?

  • ChrisHamonsChrisHamons USForum Administrator, Xamarin Team Xamurai

    You can set environmental variables via Project Options -> Run -> Configurations -> Default but since mono crashes on startup you might not get useful information.

    I would suggest launching your bundle from the command line (as my example did). That's the best way forward when you crash super early in your process launch.

  • jlaasejlaase USMember

    Chris,

    I was able to get the log information that I needed and I can see that my application is trying to local the libcef.dll. It looked for it as a dylib and and as an .so but it never looked for a Framework. Is it possible to get a mono app to load a Framework or do I need to figure out a way to get the Framework as as dylib?

            2017-12-03 21:41:54.296 CEFTest[1289:49185] info: DllImport error loading library 'libcef': 'dlopen(libcef, 9): image not found'.
            2017-12-03 21:41:54.296 CEFTest[1289:49185] info: DllImport error loading library 'libcef.dylib': 'dlopen(libcef.dylib, 9): image not found'.
            2017-12-03 21:41:54.297 CEFTest[1289:49185] info: DllImport error loading library 'libcef.so': 'dlopen(libcef.so, 9): image not found'.
            2017-12-03 21:41:54.298 CEFTest[1289:49185] info: DllImport error loading library 'libcef.bundle': 'dlopen(libcef.bundle, 9): image not found'.
            2017-12-03 21:41:54.298 CEFTest[1289:49185] info: DllImport error loading library 'libcef': 'dlopen(libcef, 9): image not found'.
    

    Thanks,

    Josh

  • ChrisHamonsChrisHamons USForum Administrator, Xamarin Team Xamurai

    So you could use DLLMap (http://www.mono-project.com/docs/advanced/pinvoke/dllmap/) to do this, by making a config file next to the library (copy into into the MonoBundle).

    Or you could try dlopen'ing the framework first, maybe mono checks loaded libraries first (I'd have to do some digging).

  • jlaasejlaase USMember

    I finally have some time to get back onto this project and I have made some steps forward. While I was never able to get my own config file working, I noticed that the default build put a config file into my bundle. By editing this config file, I was able to map the libcef.dll to the framework using this:

    <dllmap dll="libcef" target="Chromium Embedded Framework"/>

    Unfortunately, I am still getting an error that it can not find the file Chromium Embedded Framework. When I look at the mono logs, I see that is is trying to load the file from the correct directory. The directory where the file is located is /Users/jlaase/Dev/CEFTest/CEFTest/bin/Debug/CEFTest.app/Contents/MonoBundle/. The problem is that the the framework is getting a lib added to the start when mono tries to load it. Any ideas why the lib would be added?

    If it would help diagnosis this problem, I can provide my sample project.

    10:16:12.381 CEFTest[69894:2789400] info: DllImport attempting to load: 'Chromium Embedded Framework'. 2018-01-24 10:16:12.381 CEFTest[69894:2789400] info: DllImport error loading library '/Users/jlaase/Dev/CEFTest/CEFTest/bin/Debug/CEFTest.app/Contents/MonoBundle/libChromium Embedded Framework': 'dlopen(/Users/jlaase/Dev/CEFTest/CEFTest/bin/Debug/CEFTest.app/Contents/MonoBundle/libChromium Embedded Framework, 9): image not found'. 2018-01-24 10:16:12.382 CEFTest[69894:2789400] info: DllImport error loading library '/Users/jlaase/Dev/CEFTest/CEFTest/bin/Debug/CEFTest.app/Contents/MonoBundle/libChromium Embedded Framework.dylib': 'dlopen(/Users/jlaase/Dev/CEFTest/CEFTest/bin/Debug/CEFTest.app/Contents/MonoBundle/libChromium Embedded Framework.dylib, 9): image not found'. 2018-01-24 10:16:12.382 CEFTest[69894:2789400] info: DllImport error loading library '/Users/jlaase/Dev/CEFTest/CEFTest/bin/Debug/CEFTest.app/Contents/MonoBundle/libChromium Embedded Framework.so': 'dlopen(/Users/jlaase/Dev/CEFTest/CEFTest/bin/Debug/CEFTest.app/Contents/MonoBundle/libChromium Embedded Framework.so, 9): image not found'. 2018-01-24 10:16:12.382 CEFTest[69894:2789400] info: DllImport error loading library '/Users/jlaase/Dev/CEFTest/CEFTest/bin/Debug/CEFTest.app/Contents/MonoBundle/libChromium Embedded Framework.bundle': 'dlopen(/Users/jlaase/Dev/CEFTest/CEFTest/bin/Debug/CEFTest.app/Contents/MonoBundle/libChromium Embedded Framework.bundle, 9): image not found'. 2018-01-24 10:16:12.382 CEFTest[69894:2789400] info: DllImport error loading library '/Users/jlaase/Dev/CEFTest/CEFTest/bin/Debug/CEFTest.app/Contents/lib/libChromium Embedded Framework': 'dlopen(/Users/jlaase/Dev/CEFTest/CEFTest/bin/Debug/CEFTest.app/Contents/lib/libChromium Embedded Framework, 9): image not found'. 2018-01-24 10:16:12.383 CEFTest[69894:2789400] info: DllImport error loading library '/Users/jlaase/Dev/CEFTest/CEFTest/bin/Debug/CEFTest.app/Contents/lib/libChromium Embedded Framework.dylib': 'dlopen(/Users/jlaase/Dev/CEFTest/CEFTest/bin/Debug/CEFTest.app/Contents/lib/libChromium Embedded Framework.dylib, 9): image not found'. 2018-01-24 10:16:12.383 CEFTest[69894:2789400] info: DllImport error loading library '/Users/jlaase/Dev/CEFTest/CEFTest/bin/Debug/CEFTest.app/Contents/lib/libChromium Embedded Framework.so': 'dlopen(/Users/jlaase/Dev/CEFTest/CEFTest/bin/Debug/CEFTest.app/Contents/lib/libChromium Embedded Framework.so, 9): image not found'. 2018-01-24 10:16:12.383 CEFTest[69894:2789400] info: DllImport error loading library '/Users/jlaase/Dev/CEFTest/CEFTest/bin/Debug/CEFTest.app/Contents/lib/libChromium Embedded Framework.bundle': 'dlopen(/Users/jlaase/Dev/CEFTest/CEFTest/bin/Debug/CEFTest.app/Contents/lib/libChromium Embedded Framework.bundle, 9): image not found'. 2018-01-24 10:16:12.383 CEFTest[69894:2789400] info: DllImport error loading library '/Users/jlaase/Dev/CEFTest/CEFTest/bin/Debug/CEFTest.app/Contents/Libraries/libChromium Embedded Framework': 'dlopen(/Users/jlaase/Dev/CEFTest/CEFTest/bin/Debug/CEFTest.app/Contents/Libraries/libChromium Embedded Framework, 9): image not found'. 2018-01-24 10:16:12.383 CEFTest[69894:2789400] info: DllImport error loading library '/Users/jlaase/Dev/CEFTest/CEFTest/bin/Debug/CEFTest.app/Contents/Libraries/libChromium Embedded Framework.dylib': 'dlopen(/Users/jlaase/Dev/CEFTest/CEFTest/bin/Debug/CEFTest.app/Contents/Libraries/libChromium Embedded Framework.dylib, 9): image not found'. 2018-01-24 10:16:12.384 CEFTest[69894:2789400] info: DllImport error loading library '/Users/jlaase/Dev/CEFTest/CEFTest/bin/Debug/CEFTest.app/Contents/Libraries/libChromium Embedded Framework.so': 'dlopen(/Users/jlaase/Dev/CEFTest/CEFTest/bin/Debug/CEFTest.app/Contents/Libraries/libChromium Embedded Framework.so, 9): image not found'. 2018-01-24 10:16:12.384 CEFTest[69894:2789400] info: DllImport error loading library '/Users/jlaase/Dev/CEFTest/CEFTest/bin/Debug/CEFTest.app/Contents/Libraries/libChromium Embedded Framework.bundle': 'dlopen(/Users/jlaase/Dev/CEFTest/CEFTest/bin/Debug/CEFTest.app/Contents/Libraries/libChromium Embedded Framework.bundle, 9): image not found'. 2018-01-24 10:16:12.385 CEFTest[69894:2789400] info: DllImport error loading library 'libChromium Embedded Framework': 'dlopen(libChromium Embedded Framework, 9): image not found'. 2018-01-24 10:16:12.385 CEFTest[69894:2789400] info: DllImport error loading library 'libChromium Embedded Framework.dylib': 'dlopen(libChromium Embedded Framework.dylib, 9): image not found'. 2018-01-24 10:16:12.386 CEFTest[69894:2789400] info: DllImport error loading library 'libChromium Embedded Framework.so': 'dlopen(libChromium Embedded Framework.so, 9): image not found'. 2018-01-24 10:16:12.386 CEFTest[69894:2789400] info: DllImport error loading library 'libChromium Embedded Framework.bundle': 'dlopen(libChromium Embedded Framework.bundle, 9): image not found'. 2018-01-24 10:16:12.387 CEFTest[69894:2789400] info: DllImport error loading library 'Chromium Embedded Framework': 'dlopen(Chromium Embedded Framework, 9): image not found'.

Sign In or Register to comment.