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

5

15

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:-

How can I resolve this?

VS version details:

Visual Studio 2019

.Net Framework 4.7.2

Gabionade answered 27/1, 2020 at 6:48 Comment(5)
That's a very odd name for a dll, looks like it might be from some preview build. Check the actual assembly name and build with that as a reference.Certify
@Certify Can you please be more specific? Assembly name is not available when I browse for LibGit2Sharp.Gabionade
How are you referencing libgit?Certify
You can find referencing details by going to the code file here. I just installed LibGit2Sharp from NuGet and then implemented here. I am calling GetRepositoryInformationForPath method with the repo local path. that's it.Gabionade
I have the exact same issue. Did you find a solution @TanmayBairagi?Valdovinos
A
7

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)

Asphyxiant answered 27/1, 2020 at 10:42 Comment(1)
I can find this dll in <project> -> bin -> debug -> lib -> win32 -> x64 and x86. There are two files git2-106a5f2.dll and git2-106a5f2.pdb. I tried to copy them into other folders on the project but nothing worked. Is there any other solution for that?Gabionade
V
4

I had the same issue and I solved it like this:

  1. Copy the dir folder from VisualStudioExtension -> Bin -> Debug -> lib to the root of the VisualStudioExtension project. This folder contains the DLL files required for LibGit2Sharp to work.
  2. Drag the lib folder onto the VisualStudioExtension project in Visual Studio.

enter image description here

  1. Select the dll files, right-click, Properties, and set it to Copy always and include in VSIX.

enter image description here

That worked for me.

Valdovinos answered 26/3, 2020 at 8:43 Comment(1)
Any ideas for VS 2022 new Extensibiltiy API with .NET 8?Akins
Z
3

LibGit2Sharp has a dependency on the git2-106a5f2.dll which is under [Debug|Release]\lib\win32\[x86|[x64] directory.

If that particular version is missing, you may need to reinstall LibGit2Sharp library, but uninstall LibGit2Sharp.NativeBinaries library between uninstall and install.

The following operations on NuGet packages should help:

  1. Uninstall LibGit2Sharp.
  2. Uninstall LibGit2Sharp.NativeBinaries.
  3. Install LibGit2Sharp.

Note: do not update LibGit2Sharp.NativeBinaries even if there is a newer version.

Zirconium answered 8/11, 2021 at 12:46 Comment(0)
D
1

I got the same issue. It turn out I ignored the dependecies. Installing its dependency : LibGit2Sharp.NativeBinaries sort out my problem.

Diagenesis answered 4/11, 2020 at 5:20 Comment(0)
M
1

For me, I manually installed the Debug and Release VSIX, and tested against regular VS instance and it worked fine. The LibGit2Sharp threw a DllNotFoundException only when debugging my code via the Exp version of Visual Studio 2019.

So I deleted the entire Extensions folder of the Exp verison of Visual Studio. It is the folder where the Exp version of VS installs all Plugins, like other versions of VS: %AppData%\Local\Microsoft\VisualStudio\16.0_a31c0a3aExp\Extensions

The next time I debugged my VSIX through Visual Studio, it worked. Hope this helps, I think it has something to do with extensions.en-US files inside that folder. Deleting just my plugin folder insted the Extensions folder did nothing.

Montherlant answered 8/5, 2021 at 13:9 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.