LibGit2Sharp DllNotFoundException: Unable to load DLL 'git2-106a5f2'

0

I am working on a vsix project where I need to get information about a local git directory. I am following this article. When I am using LibGit2Sharp library, I am getting an exception as described in following image and error:-

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)

How can I resolve this?

VS version details:

Visual Studio 2019

.Net Framework 4.7.2

c#
visual-studio
vsix
libgit2sharp
extensibility
asked on Stack Overflow Jan 27, 2020 by Tanmay Bairagi • edited Feb 10, 2020 by Tanmay Bairagi

1 Answer

2

LibGit2Sharp is a managed language (.NET) wrapper around a native (C) library, libgit2. It's a P/Invoke layer, plus a layer to give .NET semantics (objects, etc). This means, though, that you require both the LibGit2Sharp.dll (the managed-language side) and the git2-xxxxxxx.dll (the corresponding native library) that it calls into.

The native DLL is part of the LibGit2Sharp.NativeBinaries project that LibGit2Sharp takes a dependency on. It should be installed (transitively) when you install LibGit2Sharp itself. And although it tries to set itself up as a dependency that will be installed in the output directory, since native binaries are not well-understood in the .NET project world, this can sometimes fail, especially for more complex project types like VSIX.

Ultimately, LibGit2Sharp will look for the corresponding native DLL alongside where it's located. So within your output directory, wherever your VSIX is being executed from, try copying the git2-xxxxxxx.dll that is part of the LibGit2Sharp.NativeBinaries project to that location.

Once you've identified the correct location for the git2-xxxxxxx.dll binary to live, you should copy this as part of your installation for the project. (eg Build action: None, Copy to output directory: Copy always)

answered on Stack Overflow Jan 27, 2020 by Edward Thomson

User contributions licensed under CC BY-SA 3.0