问题
have a very simple one line console app (using monodevelop)
but getting below error.
System.TypeInitializationException: The type initializer for 'LibGit2Sharp.Core.NativeMethods' threw an exception. ---> System.DllNotFoundException: git2-e0902fb
my app has reference two nuget package
- LibGit2Sharp 0.21.0.176
- LibGit2Sharp.NativeBinaries 1.0.119
LibGit2Sharp.Repository.Init("foler path");
回答1:
libGit2Sharp
0.21.0.176 nuget does have dependency on a specific native library and it requires 'version/sha' e0902fb and that is not included in the 1.0.119
or 1.0.106
native nugets. (I always build these packages from source.)
The pre-release nuget for LibGit2Sharp
0.22.0-pre20151023210959 does include a native nuget dependency and pulls 1.0.6 version of the LibGit2Sharp.NativeBinaries
which work together.
So:
Either use the pre-release version of LibGit2Sharp
and it will pull in the 1.0.6 version of LibGit2Sharp.NativeBinaries
which provides the correct 64-bit shared library (libgit2-6aa06b6.so
) that work together:
<?xml version="1.0" encoding="utf-8"?>
<packages>## Heading ##
<package id="LibGit2Sharp" version="0.22.0-pre20151023210959" targetFramework="net45" />
<package id="LibGit2Sharp.NativeBinaries" version="1.0.106" targetFramework="net45" />
</packages>
Or:
Use the release version of LibGit2Sharp (0.21.0.176) and find if a Native Nuget is available(?) with a 64-bit linux-based libgit2-e0902fb.so
.
Or:
Use the release version of LibGit2Sharp (0.21.0.176) and build the native lib from source.
回答2:
Once you matched up native binaries package then on osx/linux you might run into error
System.DllNotFoundException: NativeBinaries/osx/libgit2-821131f.dylib
In that case rename target directory in /bin from NativeBinaries to libNativeBinaries.
For detailed discussion on this see libgit2sharp/issues/1170
来源:https://stackoverflow.com/questions/35028958/not-able-to-run-libgit2sharp-on-mono-on-ubuntu