I am trying to use the great library libgit2sharp on a Mac. Therefore I'm using Xamarin Studio to create a Mac app to read information from a Git repository.
When I use the library within a normal mono executable (target Mono / .NET4.5
, everything just works fine.
But when I create a Xamarin.Mac project, the following error occurs and I don't see a way round:
Unhandled Exception:
System.TypeInitializationException: The type initializer for 'LibGit2Sharp.Core.NativeMethods' threw an exception. ---> System.DllNotFoundException: git2-a5cf255
at (wrapper managed-to-native) LibGit2Sharp.Core.NativeMethods:git_libgit2_init ()
at LibGit2Sharp.Core.NativeMethods+LibraryLifetimeObject..ctor () [0x00006] in <9f09b2b30ef34f0b8a3a0a6bdde2be90>:0
at LibGit2Sharp.Core.NativeMethods..cctor () [0x00058] in <9f09b2b30ef34f0b8a3a0a6bdde2be90>:0
--- End of inner exception stack trace ---
at LibGit2Sharp.Core.Proxy.git_repository_open (System.String path) [0x00008] in <9f09b2b30ef34f0b8a3a0a6bdde2be90>:0
at LibGit2Sharp.Repository..ctor (System.String path, LibGit2Sharp.RepositoryOptions options, LibGit2Sharp.Repository+RepositoryRequiredParameter requiredParameter) [0x0007e] in <9f09b2b30ef34f0b8a3a0a6bdde2be90>:0
[ERROR] FATAL UNHANDLED EXCEPTION: System.TypeInitializationException: The type initializer for 'LibGit2Sharp.Core.NativeMethods' threw an exception. ---> System.DllNotFoundException: git2-a5cf255
at (wrapper managed-to-native) LibGit2Sharp.Core.NativeMethods:git_libgit2_init ()
at LibGit2Sharp.Core.NativeMethods+LibraryLifetimeObject..ctor () [0x00006] in <9f09b2b30ef34f0b8a3a0a6bdde2be90>:0
at LibGit2Sharp.Core.NativeMethods..cctor () [0x00058] in <9f09b2b30ef34f0b8a3a0a6bdde2be90>:0
--- End of inner exception stack trace ---
at LibGit2Sharp.Core.Proxy.git_repository_open (System.String path) [0x00008] in <9f09b2b30ef34f0b8a3a0a6bdde2be90>:0
at LibGit2Sharp.Repository..ctor (System.String path, LibGit2Sharp.RepositoryOptions options, LibGit2Sharp.Repository+RepositoryRequiredParameter requiredParameter) [0x0007e] in <9f09b2b30ef34f0b8a3a0a6bdde2be90>:0
When googling around, I found a lot of topics closing with "build libgit2sharp on your machine to get the correct .dylib files". This may have been a problem in the past, but not anymore so this did not help me. As said, I can easily use libgit2sharp with a mono executable.
By the way, I cannot use the Nuget package "libgit2sharp" because it says that the Xamarin.Mac-target is not compatible. I'm using the package "libgit2sharp.portable" which throws no error on install- or compile-time. It's just that error message from above in runtime.
My sample application is available to download here: https://files.fm/u/7eq55jjq
Any suggestions to get around this? Thanks!
Update The error might hint that the path to the dylib is wrong ("DLL not found"), but that's not true. The file is exactly where it should be.