【发布时间】:2017-04-13 22:10:57
【问题描述】:
我正在尝试在 Mac 上使用出色的库 libgit2sharp。因此,我使用 Xamarin Studio 创建了一个 Mac 应用程序来从 Git 存储库中读取信息。
当我在普通的单声道可执行文件(目标 Mono / .NET4.5)中使用该库时,一切正常。
但是当我创建一个 Xamarin.Mac 项目时,会出现以下错误,并且我看不到解决方法:
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
在谷歌搜索时,我发现很多主题都以 “在您的机器上构建 libgit2sharp 以获取正确的 .dylib 文件”结束。这在过去可能是一个问题,但现在不是了,所以这对我没有帮助。如前所述,我可以轻松地将 libgit2sharp 与单声道可执行文件一起使用。
顺便说一句,我不能使用 Nuget 包“libgit2sharp”,因为它说 Xamarin.Mac 目标不兼容。我正在使用包“libgit2sharp.portable”,它在安装或编译时不会引发错误。这只是运行时上面的错误消息。
我的示例应用程序可在此处下载:https://files.fm/u/7eq55jjq
有什么建议可以解决这个问题吗?谢谢!
更新 该错误可能暗示 dylib 的路径错误(“找不到 DLL”),但事实并非如此。该文件正是它应该在的位置。
【问题讨论】:
标签: c# git macos xamarin.mac libgit2sharp