14

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

Community
  • 1
  • 1
Tanmay Bairagi
  • 564
  • 5
  • 25
  • 1
    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. – Richard Jan 27 '20 at 07:46
  • @Richard Can you please be more specific? Assembly name is not available when I browse for LibGit2Sharp. – Tanmay Bairagi Jan 27 '20 at 09:51
  • How are you referencing libgit? – Richard Jan 27 '20 at 09:53
  • You can find referencing details by going to the code file [here](https://drive.google.com/open?id=1WhvlWpXFXpq_kIhCLIm4hz-jzrNHIJnx). I just installed LibGit2Sharp from NuGet and then implemented here. I am calling GetRepositoryInformationForPath method with the repo local path. that's it. – Tanmay Bairagi Jan 27 '20 at 10:15
  • I have the exact same issue. Did you find a solution @TanmayBairagi? – Jonas Johansson Mar 26 '20 at 08:09

5 Answers5

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)

Edward Thomson
  • 74,857
  • 14
  • 158
  • 187
  • I can find this dll in -> 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? – Tanmay Bairagi Feb 10 '20 at 14:21
3

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.

Jonas Johansson
  • 322
  • 1
  • 8
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.

Dariusz Woźniak
  • 9,640
  • 6
  • 60
  • 73
1

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

purnadika
  • 282
  • 2
  • 12
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.

Sajal
  • 41
  • 6