我在OSX 10.9.5上使用Xamarin Studio 5.7和Mono 3.12。使用NuGet我下载了libgit2sharp库。我在编写代码时能够使用这些类,没有编译器错误。但是在运行时我收到以下错误:
Unhandled Exception:
System.TypeInitializationException: An exception was thrown by the type initializer for LibGit2Sharp.Core.NativeMethods ---> System.DllNotFoundException: git2-91fa31f
at (wrapper managed-to-native) LibGit2Sharp.Core.NativeMethods:git_threads_init ()
at LibGit2Sharp.Core.NativeMethods+LibraryLifetimeObject..ctor () [0x00000] in <filename unknown>:0
at LibGit2Sharp.Core.NativeMethods..cctor () [0x00000] in <filename unknown>:0
--- End of inner exception stack trace ---
at LibGit2Sharp.Core.Proxy.git_repository_open (System.String path) [0x00000] in <filename unknown>:0
at LibGit2Sharp.Repository..ctor (System.String path, LibGit2Sharp.RepositoryOptions options) [0x00000] in <filename unknown>:0
[ERROR] FATAL UNHANDLED EXCEPTION: System.TypeInitializationException: An exception was thrown by the type initializer for LibGit2Sharp.Core.NativeMethods ---> System.DllNotFoundException: git2-91fa31f
at (wrapper managed-to-native) LibGit2Sharp.Core.NativeMethods:git_threads_init ()
at LibGit2Sharp.Core.NativeMethods+LibraryLifetimeObject..ctor () [0x00000] in <filename unknown>:0
at LibGit2Sharp.Core.NativeMethods..cctor () [0x00000] in <filename unknown>:0
--- End of inner exception stack trace ---
at LibGit2Sharp.Core.Proxy.git_repository_open (System.String path) [0x00000] in <filename unknown>:0
at LibGit2Sharp.Repository..ctor (System.String path, LibGit2Sharp.RepositoryOptions options) [0x00000] in <filename unknown>:0
似乎抱怨它无法找到git2-91fa31f
dll但是当我查看packages文件夹时,我可以看到该dll确实存在。
有没有人见过这个或者知道我能做些什么来解决它?
更新
我按照@ nulltoken的说明操作并下载了libgit2源代码。使用cmake -DCMAKE_BUILD_TYPE:STRING=RelWithDebInfo -DBUILD_CLAR:BOOL=OFF -DUSE_SSH=OFF -DENABLE_TRACE=ON -DLIBGIT2_FILENAME=git2-91fa31f -DCMAKE_OSX_ARCHITECTURES="i386;x86_64" ..
然后cmake --build .
这产生了一个名为libgit2-91fa31f.dylib
的文件。我将此文件放在bin/Debug
目录中,其中我的项目的exe是LibGit2Sharp.dll
。但是现在当我运行程序时,我得到以下内容:
Unhandled Exception:
System.TypeInitializationException: An exception was thrown by the type initializer for LibGit2Sharp.Core.NativeMethods ---> System.EntryPointNotFoundException: git_threads_init
at (wrapper managed-to-native) LibGit2Sharp.Core.NativeMethods:git_threads_init ()
at LibGit2Sharp.Core.NativeMethods+LibraryLifetimeObject..ctor () [0x00000] in <filename unknown>:0
at LibGit2Sharp.Core.NativeMethods..cctor () [0x00000] in <filename unknown>:0
--- End of inner exception stack trace ---
at LibGit2Sharp.Core.Proxy.git_repository_open (System.String path) [0x00000] in <filename unknown>:0
at LibGit2Sharp.Repository..ctor (System.String path, LibGit2Sharp.RepositoryOptions options) [0x00000] in <filename unknown>:0
[ERROR] FATAL UNHANDLED EXCEPTION: System.TypeInitializationException: An exception was thrown by the type initializer for LibGit2Sharp.Core.NativeMethods ---> System.EntryPointNotFoundException: git_threads_init
at (wrapper managed-to-native) LibGit2Sharp.Core.NativeMethods:git_threads_init ()
at LibGit2Sharp.Core.NativeMethods+LibraryLifetimeObject..ctor () [0x00000] in <filename unknown>:0
at LibGit2Sharp.Core.NativeMethods..cctor () [0x00000] in <filename unknown>:0
--- End of inner exception stack trace ---
at LibGit2Sharp.Core.Proxy.git_repository_open (System.String path) [0x00000] in <filename unknown>:0
at LibGit2Sharp.Repository..ctor (System.String path, LibGit2Sharp.RepositoryOptions options) [0x00000] in <filename unknown>:0
我有一种感觉,我搞砸了cmake部分。这是对的吗?
答案 0 :(得分:1)
LibGit2Sharp是与本机libgit2库的.Net绑定。
该项目通过使用持续集成服务器( Travis 和 AppVeyor <确保所有测试在Win 32/64,Linux和MacOsX上运行/强>)。
但是,目前LibGit2Sharp NuGet包只包含Windows本机编译的二进制文件,因此无法在Linux / MacOsX上按原样使用。为了在这些环境中使用LibGit2Sharp,您必须自己构建libgit2。
为了实现这一目标,您需要 CMake 。
您可以从CI服务器使用的 build.libgit2sharp.sh script 中获得灵感。
在 Issue 中,Therzork,一个Xamariner(以及一个LibGit2sharp核心撰稿人),分享了有关在MacOsX上构建的一些指导。
我有一种感觉,我搞砸了cmake部分。这是对的吗?
我认为CMake部分很好。提出的例外是System.EntryPointNotFoundException
。这意味着LibGit2Sharp尝试从libgit2调用一个方法,该方法要么不存在,要么其签名(参数,类型......的数量)与所暴露的方式不匹配。
实际上,每个版本的LibGit2Sharp都针对特定版本的libgit2。 libgit2缩写为commit sha用于确切期望libgit2的版本。
版本v0.20.1期望在提交91fa3af中对libgit2的编译版本起作用(对于每个LibGit2sharp提交,您可以通过查看libgit2子模块来检查预期的libgit2版本(例如, v0.20.1 强>))。
我的猜测是你实际上正在构建一个不同的libigt2提交(可能是最新的提交)。为了构建commit 91fa31f,在shell中运行以下git命令行:
$ git clone https://github.com/libgit2/libgit2
$ cd libgit2
$ git checkout 91fa31f
然后运行你的CMake魔法。生成的二进制文件现在应该符合LibGit2Sharp的预期。
答案 1 :(得分:0)
libgit2sharp需要安装libgit2。你安装了吗?