DllNotFoundException:无法加载DLL'git2-106a5f2'

问题描述 投票:0回答:1

我正在一个vsix项目中,我需要获取有关本地git目录的信息。我正在关注this文章。当我使用LibGit2Sharp库时,出现如下图所示的异常和错误:-

System.TypeInitializationException
  HResult=0x80131534
  Message=The type initializer for 'LibGit2Sharp.Core.NativeMethods' threw an exception.
  Source=LibGit2Sharp
  StackTrace:
   at LibGit2Sharp.Core.NativeMethods.git_repository_open_ext(git_repository*& repository, FilePath path, RepositoryOpenFlags flags, FilePath ceilingDirs)
   at LibGit2Sharp.Core.Proxy.git_repository_open_ext(String path, RepositoryOpenFlags flags, String ceilingDirs)
   at LibGit2Sharp.Repository.IsValid(String path)
   at CodeReviewMain.RepositoryInformation.GetRepositoryInformationForPath(String path) in E:\IMPORTANT\CodeReviewMain\CodeReviewMain\RepositoryInformation.cs:line 14
   at CodeReviewMain.GitForm.SetTextOnUrlTextbox() in E:\IMPORTANT\CodeReviewMain\CodeReviewMain\GitForm.cs:line 25
   at CodeReviewMain.GitForm..ctor() in E:\IMPORTANT\CodeReviewMain\CodeReviewMain\GitForm.cs:line 20
   at CodeReviewMain.Form1.btnSaveSendDirectories(Object sender, EventArgs e) in E:\IMPORTANT\CodeReviewMain\CodeReviewMain\Form1.cs:line 303
   at System.Windows.Forms.Control.OnClick(EventArgs e)
   at System.Windows.Forms.Button.OnClick(EventArgs e)
   at System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent)
   at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
   at System.Windows.Forms.Control.WndProc(Message& m)
   at System.Windows.Forms.ButtonBase.WndProc(Message& m)
   at System.Windows.Forms.Button.WndProc(Message& m)
   at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
   at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
   at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
   at System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg)
   at System.Windows.Forms.Application.ThreadContext.LocalModalMessageLoop(Form form)

Inner Exception 1:
DllNotFoundException: Unable to load DLL 'git2-106a5f2': The specified module could not be found. (Exception from HRESULT: 0x8007007E)

我该如何解决?

VS版本详细信息:

Visual Studio 2019

。Net Framework 4.7.2

c# visual-studio vsix libgit2sharp extensibility
1个回答
1
投票

LibGit2Sharp是围绕本机(C)库libgit2的托管语言(.NET)包装。它是一个P/Invoke层,再加上一个给出.NET语义(对象等)的层。但是,这意味着您需要both LibGit2Sharp.dll(托管语言端)调用它的git2-xxxxxxx.dll(相应的本机库)。

本地DLL是LibGit2Sharp依赖的LibGit2Sharp.NativeBinaries项目的一部分。当您自己安装LibGit2Sharp时,应该(以过渡方式)安装它。而且,尽管它尝试将自身设置为将安装在输出目录中的依赖项,但由于本机二进制文件在.NET项目世界中并未得到很好的理解,因此有时可能会失败,尤其是对于像VSIX这样的更复杂的项目类型而言。] >

最终,LibGit2Sharp将在其所在位置旁边寻找相应的本机DLL。因此,在输出目录中,无论从哪里执行VSIX,请尝试将LibGit2Sharp.NativeBinaries项目中的git2-xxxxxxx.dll复制到该位置。

一旦您确定了git2-xxxxxxx.dll二进制文件的正确生存位置,则应将此复制为项目安装的一部分。 (例如构建操作

:无,复制到输出目录:始终复制)
© www.soinside.com 2019 - 2024. All rights reserved.