Nerdbank.GitVersioning: Visual Studio Code/OmniSharp on Ubuntu 18.04: DllNotFoundException

Visual Studio Code/OmniSharp fails to properly load .csproj projects which contain a reference to NerdBank.GitVersioning. I’ve tried with the latest version of the 3.0 series of nbgv, both from NuGet and the CI feed.

Don’t have much time to deep dive into this at the moment. Here are a couple of things I’ve noticed:

  • Compiling using dotnet build works properly.
  • I’m a bit confused by the lib/ part in the path (lib/linux-x64/libgit2-572e4d8.so)
  • linux-x64/libgit2-572e4d8.so should load fine on my platform, see the ldd output below.

Here’s the full stack error:

[fail]: OmniSharp.MSBuild.ProjectLoader
        The "Nerdbank.GitVersioning.Tasks.GetBuildVersion" task failed unexpectedly.
System.TypeInitializationException: The type initializer for 'LibGit2Sharp.Core.NativeMethods' threw an exception. ---> System.DllNotFoundException: lib/linux-x64/libgit2-572e4d8.so assembly:<unknown assembly> type:<unknown type> member:(null)
  at (wrapper managed-to-native) LibGit2Sharp.Core.NativeMethods.git_libgit2_init()
  at LibGit2Sharp.Core.NativeMethods.InitializeNativeLibrary () [0x00002] in <5eedf8e7a87843a29f618ebab30cacf5>:0 
  at LibGit2Sharp.Core.NativeMethods..cctor () [0x00045] in <5eedf8e7a87843a29f618ebab30cacf5>:0 
   --- End of inner exception stack trace ---
  at LibGit2Sharp.Core.Proxy.git_libgit2_opts_set_search_path (LibGit2Sharp.ConfigurationLevel level, System.String path) [0x00000] in <5eedf8e7a87843a29f618ebab30cacf5>:0 
  at LibGit2Sharp.GlobalSettings.SetConfigSearchPaths (LibGit2Sharp.ConfigurationLevel level, System.String[] paths) [0x0001a] in <5eedf8e7a87843a29f618ebab30cacf5>:0 
  at Nerdbank.GitVersioning.GitExtensions.OpenGitRepo (System.String pathUnderGitRepo, System.Boolean useDefaultConfigSearchPaths) [0x00025] in <e6b3f9410fa9409c8eeff285038f1773>:0 
  at Nerdbank.GitVersioning.VersionOracle.Create (System.String projectDirectory, System.String gitRepoDirectory, Nerdbank.GitVersioning.ICloudBuild cloudBuild, System.Nullable`1[T] overrideBuildNumberOffset, System.String projectPathRelativeToGitRepoRoot) [0x00017] in <e6b3f9410fa9409c8eeff285038f1773>:0 
  at Nerdbank.GitVersioning.Tasks.GetBuildVersion.ExecuteInner () [0x000c5] in <0c993f0ed37445e28de1993f9f821a67>:0 
  at MSBuildExtensionTask.ContextAwareTask.Execute () [0x0005e] in <0c993f0ed37445e28de1993f9f821a67>:0 
  at Microsoft.Build.BackEnd.TaskExecutionHost.Microsoft.Build.BackEnd.ITaskExecutionHost.Execute () [0x00029] in <b695b16788dd418cbe8b4d98f7a92ff3>:0 
  at Microsoft.Build.BackEnd.TaskBuilder.ExecuteInstantiatedTask (Microsoft.Build.BackEnd.ITaskExecutionHost taskExecutionHost, Microsoft.Build.BackEnd.Logging.TaskLoggingContext taskLoggingContext, Microsoft.Build.BackEnd.TaskHost taskHost, Microsoft.Build.BackEnd.ItemBucket bucket, Microsoft.Build.BackEnd.TaskExecutionMode howToExecuteTask) [0x002a9] in <b695b16788dd418cbe8b4d98f7a92ff3>:0 

Here’s the ldd output:

$ ldd ~/.nuget/packages/nerdbank.gitversioning/3.0.41/build/runtimes/linux-x64/native/libgit2-572e4d8.so 
	linux-vdso.so.1 (0x00007fffb69b1000)
	librt.so.1 => /lib/x86_64-linux-gnu/librt.so.1 (0x00007f7ee672a000)
	libpthread.so.0 => /lib/x86_64-linux-gnu/libpthread.so.0 (0x00007f7ee650b000)
	libssl.so.1.0.0 => /usr/lib/x86_64-linux-gnu/libssl.so.1.0.0 (0x00007f7ee62a3000)
	libcrypto.so.1.0.0 => /usr/lib/x86_64-linux-gnu/libcrypto.so.1.0.0 (0x00007f7ee5e60000)
	libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007f7ee5a6f000)
	/lib64/ld-linux-x86-64.so.2 (0x00007f7ee6c5d000)
	libdl.so.2 => /lib/x86_64-linux-gnu/libdl.so.2 (0x00007f7ee586b000)

Leaving this here in case anyone else sees a similar problem (or even better, knows how to fix it).

About this issue

  • Original URL
  • State: closed
  • Created 5 years ago
  • Reactions: 9
  • Comments: 36 (8 by maintainers)

Commits related to this issue

Most upvoted comments

Or maybe should we be poking Omnisharp to move to .NET Core instead of Mono?

Yep, this basically breaks using VS Code for C# projects that use GitVersioning, because the project load failure means no Intellisense, no F12, etc.

@reinaldocoelho Can you please try the latest 3.4 beta? It should totally fix this for you.

Hi @AArnott, sorry for the long time to anwer. I have tried the version 3.4.165-alpha and it’s solved the problem to me. To make this work, I’v cleaned dotnet environment with dotnet clean and reopen visual studio code.

Thank you for the answer 😃

In the time of problem I´m using the version 3.3.37. I will try that and return 😃 Thank you.

I’m using ubuntu 20.04 and having same OmniSharp error. My case was solved when update file: /home/user/.nuget/packages/nerdbank.gitversioning/3.3.37/build/MSBuildFull/lib/linux-x64/libgit2-106a5f2.so with my SO version, in this case: /home/user/.nuget/packages/nerdbank.gitversioning/3.3.37/build/runtimes/ubuntu.18.04-x64/native/libgit2-106a5f2.so

The command I’m run was: cp /home/user/.nuget/packages/nerdbank.gitversioning/3.3.37/build/runtimes/ubuntu.18.04-x64/native/libgit2-106a5f2.so /home/user/.nuget/packages/nerdbank.gitversioning/3.3.37/build/MSBuildFull/lib/linux-x64/libgit2-106a5f2.so

After replace the .so file, OmniSharp work’s well. I hope this help somebody!

Coming from google, on debian 10, the fix from https://github.com/dotnet/Nerdbank.GitVersioning/issues/482#issuecomment-636476942 works wonders.

Thanks for that, @kglassmire. Yes, I see now that on an Ubuntu 19.10 that it fails. I’m not sure what I was looking at before.

ldd ~/.nuget/packages/nerdbank.gitversioning/3.1.74/build/MSBuildFull/lib/linux-x64/libgit2-106a5f2.so                                 
        linux-vdso.so.1 (0x00007ffc00100000)
        librt.so.1 => /lib/x86_64-linux-gnu/librt.so.1 (0x00007efbff398000)
        libpthread.so.0 => /lib/x86_64-linux-gnu/libpthread.so.0 (0x00007efbff375000)
        libssl.so.1.0.0 => not found
        libcrypto.so.1.0.0 => not found
        libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007efbff184000)
        /lib64/ld-linux-x86-64.so.2 (0x00007efbff6d2000)

So ya, it’s typical ssl dependency problems. So as you say, it will hopefully be fixed when libgit2sharp offers a managed HTTPS layer.

Yeah I went back and looked again and see where I went wrong.

I thought they were both Ubuntu 18.04 but one was actually 19.04. It is hard to tell because they are both the “Lubuntu” flavor of Ubuntu and they don’t look that different to me in terms of desktop between 18.04 and 19.04

The one that wasn’t working though was 19.04. I confirmed that your fix works with v3.1.74 and Ubuntu 18.04 as this issue is titled. Thank you for the fix!

@AArnott It looks like the folder structure for the linux binary you’re bundling needs to be updated.

I think something is wrong with either the dll.config file or the directory structure of the libgit2 binaries shipped with the nuget package. See below that the linux binary is in the lib/linux/x86_64 folder, but the dll.config file points to lib/linux-x64. In fact, updating the dll.config file to match with the actual directory structure fixed my problem. I’m using Arch linux.

$ pwd
/home/user1/.nuget/packages/nerdbank.gitversioning/3.0.50/build/MSBuildFull
$ tree lib
lib
├── linux
│   └── x86_64
│       └── libgit2-572e4d8.so
├── osx
│   └── libgit2-572e4d8.dylib
└── win32
    ├── x64
    │   └── git2-572e4d8.dll
    └── x86
        └── git2-572e4d8.dll

6 directories, 4 files
$ cat LibGit2Sharp.dll.config 
<configuration>
    <dllmap os="linux" cpu="x86-64" wordsize="64" dll="git2-572e4d8" target="lib/linux-64/libgit2-572e4d8.so" />
    <dllmap os="osx" cpu="x86,x86-64" dll="git2-572e4d8" target="lib/osx/libgit2-572e4d8.dylib" />
</configuration>