Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Visual Studio Code/OmniSharp on Ubuntu 18.04: DllNotFoundException #417

Closed
qmfrederik opened this issue Dec 17, 2019 · 36 comments · Fixed by #457
Closed

Visual Studio Code/OmniSharp on Ubuntu 18.04: DllNotFoundException #417

qmfrederik opened this issue Dec 17, 2019 · 36 comments · Fixed by #457
Labels
Milestone

Comments

@qmfrederik
Copy link
Contributor

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).

@jkeech
Copy link
Contributor

jkeech commented Dec 26, 2019

I'm also running into this on a slightly older version of NBGV when using a VS Online environment (which is running the remote VS Code backend in a linux container). It's complicated further by the fact that Debian 9 doesn't include libssl 1.0.0 or libcrypto 1.0.0. Instead, it includes OpenSSL 1.0.2 and 1.1.

$ lsb_release -sd
Debian GNU/Linux 9.11 (stretch)
$ ldd /var/nuget/nerdbank.gitversioning/2.3.38/build/runtimes/linux-x64/native/libgit2-a904fc6.so 
        linux-vdso.so.1 (0x00007ffe19ed3000)
        librt.so.1 => /lib/x86_64-linux-gnu/librt.so.1 (0x00007ff0a6fd3000)
        libpthread.so.0 => /lib/x86_64-linux-gnu/libpthread.so.0 (0x00007ff0a6db6000)
        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 (0x00007ff0a6a17000)
        /lib64/ld-linux-x86-64.so.2 (0x00007ff0a7505000)

@bradwilson
Copy link

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

@bradwilson
Copy link

$ lsb_release -sd
Ubuntu 18.04.3 LTS

Strangely enough, it only affects Omnisharp. I don't have any issue doing builds from the command line.

@bradwilson
Copy link

bradwilson commented Jan 15, 2020

Starting OmniSharp server at 1/15/2020, 1:07:37 PM
    Target: /home/bradwilson/dev/xunit/xunit.analyzers/xunit.analyzers.sln

OmniSharp server started with Mono 6.8.0.
    Path: /home/bradwilson/.vscode-server/extensions/ms-vscode.csharp-1.21.9/.omnisharp/1.34.9/omnisharp/OmniSharp.exe
    PID: 4434

[...]

[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 <444099983adb4a12847c0a9f90693abe>: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 <444099983adb4a12847c0a9f90693abe>:0 
  at Nerdbank.GitVersioning.Tasks.GetBuildVersion.ExecuteInner () [0x000c5] in <1f9ecc7fe0a04fccae1204f855ceea16>:0 
  at MSBuildExtensionTask.ContextAwareTask.Execute () [0x0005e] in <1f9ecc7fe0a04fccae1204f855ceea16>:0 
  at Microsoft.Build.BackEnd.TaskExecutionHost.Microsoft.Build.BackEnd.ITaskExecutionHost.Execute () [0x00029] in <521c9f0b2fea413a92d6bc8b291724e7>: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 <521c9f0b2fea413a92d6bc8b291724e7>:0 

@qmfrederik
Copy link
Contributor Author

Omnisharp runs on Mono, not CoreCLR. That may be relevant.

@clairernovotny
Copy link
Member

Tagging @ethomson as this appears to pertain to LibGit2

@ethomson
Copy link

I don't understand how LibGit2Sharp loads libgit2 anymore. @bording might have some insight here?

@bording
Copy link

bording commented Jan 17, 2020

Which version of LibGit2Sharp is being used?

@bradwilson
Copy link

That's master. Looks like the latest release used 0.27.0-preview-0007.

@bording
Copy link

bording commented Jan 21, 2020

Unfortunately, I'm not sure there's going to be a great answer here. Currently, the LibGit2Sharp native binaries package requires different native binaries for different linux platforms. When using .NET Core, there is a built-in mechanism to choose the correct binary using the platform RID.

Mono doesn't have anything like that. What it supports is much more limited. The native binaries package includes a LibGit2Sharp.dll.config file to configure which binary Mono is going to use. It looks like this:

<configuration>
    <dllmap os="linux" cpu="x86-64" wordsize="64" dll="git2-572e4d8" target="lib/linux-x64/libgit2-572e4d8.so" />
    <dllmap os="osx" cpu="x86,x86-64" dll="git2-572e4d8" target="lib/osx/libgit2-572e4d8.dylib" />
</configuration>

That's why you see it trying to use the linux-x64 version of the binary. There is no way to vary this based on distro/RID, so I had to pick a single value for the file.

When running on Ubuntu 18.04, you would need to be using lib/ubuntu.18.04-x64/libgit2-572e4d8.so instead.

@bradwilson
Copy link

@AArnott Any chance of dumping libgit2sharp in favor of something else, like shelling out to the git CLI?

@bradwilson
Copy link

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

@AArnott
Copy link
Collaborator

AArnott commented Jan 21, 2020

I'm afraid the git CLI can't substitute for what NB.GV is doing. We're looking at each commit in history individually, scanning the trees/blobs and making decisions at each point. So we'd have to spawn git.exe (or linux equivalent) half a dozen times per commit in history to replace what we use libgit2sharp for here. The perf of that would undoubtedly be abominable. NB.GV already shows up on build perf stats for large repos so I don't want to do anything to make it slower.

But we do need to make it work. We're brainstorming options over in the conversation on this PR: libgit2/libgit2sharp#1618

@qmfrederik
Copy link
Contributor Author

So, I got nbgv to work inside OmniSharp on Ubuntu 19.10.

The general idea is to have a MSBuild task which calls dlopen to load libgit2-{rev}.so from the correct location before any of the NB.GV tasks run. The P/Invoke into libgit2-{rev}.so from LibGit2Sharp then re-uses the library which was previously loaded, and things "just work".

There were two gotchas:

  • I had to remove the LibGit2Sharp.dll.config file with the DllMap entries
  • The soname for libgit2-572e4d8.so is libgit2-572e4d8.so.28 (i.e. with the .28 suffix). I had to patch the soname to be exactly libgit2-572e4d8.so for this to work.

@AArnott , is this an approach you're willing to consider? Creating a MSBuild task which pre-loads libgit2-{rev}.so (preferably only when running on Mono) and excluding the LibGit2Sharp.dll.config file from the NuGet package seems easy enough. Patching the soname could be done as part of the build, or we could ask libgit2 to align the soname and the name used in the P/Invoke signatures.

The task could look like this:

using System;
using System.Runtime.InteropServices;
using System.Text;
using Microsoft.Build.Utilities;

namespace NerdBank.GitVersioning.Mono
{
    public class LoadLibGit2Task : Task
    {
        private const string libdl = "libdl.so.2";

        [DllImport(libdl)]
        public static unsafe extern void* dlopen(byte* filename, int flags);

        public static int RTLD_LAZY = 1;

        public unsafe override bool Execute()
        {
            this.Log.LogMessage("Starting LoadLibGit2Task");

            const string libName = "path/to/runtimes/ubuntu.18.04-x64/native/libgit2-572e4d8.so";

            fixed (byte* filename = Encoding.UTF8.GetBytes(libName))
            {
                var libHandle = new IntPtr(dlopen(filename, RTLD_LAZY));
                this.Log.LogMessage($"Loaded libgit2.so as {libHandle}");
            }

            return true;
        }
    }
}

and be plugged into MSBuild like this:

  <UsingTask TaskName="NerdBank.GitVersioning.Mono.LoadLibGit2Task" AssemblyFile="path-to/nbgv-mono.dll" />

  <Target Name="LoadLibgit2" BeforeTargets="GetBuildVersion">
    <Message Text="Loading Libgit2" />
    <NerdBank.GitVersioning.Mono.LoadLibGit2Task />
  </Target>

@bording
Copy link

bording commented Jan 23, 2020

@qmfrederik In addition to the unpleasantness around needing to modify the binaries (soname patching) and needing to restrict this to mono-on-linux only, the other problem with your proposed approach is that it is hardcoded to the Ubuntu 18.04 binary. What about all the other distros that it could be run on? You would need to implement logic that understood the RID graph and all the binaries that ship in the package (which can change over time) to know which lib to try and load.

@qmfrederik
Copy link
Contributor Author

I'd initially scope it to do its magic only on Ubuntu (and perhaps Debian) releases with OpenSSL 1.1. You could read the data from /etc/lsb-release in a very defensive manner, or use Microsoft.DotNet.PlatformAbstractions, apparently.

An alternative approach would be to just try & load all the different copies of libgit2-{rev}.so that are can be found in runtimes/, similar to what libgit2/libgit2sharp#1714 does.

It's very unpleasant for sure, but I don't see any other options at the moment. And I'd really like to have OmniSharp working in Visual Studio Code 😄 .

@bording
Copy link

bording commented Jan 24, 2020

@qmfrederik One other thing, are you sure that calling dlopen like that actually gets the behavior of using that version instead of the one that would be chosen normally? Based on previous conversations, I was under the impression that would not work (loading it in advance would only work on Windows) which is why we stopped trying to do that directly in LibGit2Sharp.

@qmfrederik
Copy link
Contributor Author

@bording Using dlopen like that does work, if

  • the soname in the library matches the name used in the DllImport declaration
  • there's no DllMap entry for that library

I had some issues in the past where dlopen couldn't be located in libdl on RHEL/CentOS (I think it's located in libc), but I would need to double-check that.

I've created a prototype fix for this (for Ubuntu) at https://github.com/qmfrederik/nbgv-mono. It works for me by adding a package reference to nbgv-mono if you remove LibGit2Sharp.dll.config.

Let's see if I can add Debian support, as I've noticed @jkeech seems to be on Debian 9.

@qmfrederik
Copy link
Contributor Author

@jkeech @bradwilson If you're up to it, can you give this a try:

  1. Add a PackageReference to nbgv-mono version 1.0.5 to your project
  2. Delete rm ~/.nuget/packages/nerdbank.gitversioning/3.0.50/build/MSBuildFull/LibGit2Sharp.dll.config (change 3.0.50 to the version of nbgv you're using)
  3. Open the project in Visual Studio Code or run Mono's copy of MSBuild.

This works for me, let me know if that's the case for you guys, too.

@qmfrederik
Copy link
Contributor Author

@bording FYI - I got a suggestion in the Mono Gitter channel to "build against gnutls not OpenSSL. The ABI is much much more cross-distro-friendly". Coming from someone who spends a lot of time packaging for different distros.

@hlee-gs1us
Copy link

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>

@bording
Copy link

bording commented Feb 24, 2020

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

@kglassmireacr
Copy link

kglassmireacr commented Mar 28, 2020

After altering the LibGit2Sharp.dll.config to point at the real path under the lib folder for the dllmap os="linux", my intellisense started working again in VS Code.

EDIT:
@AArnott false alarm. I'm not sure what I did, but I tried to duplicate these steps on a different (work) machine and it is not working. Both machines were same underlying OS though (Ubuntu 19.04, not 18.04). My apologies. Sorry to get your hopes up.

@AArnott
Copy link
Collaborator

AArnott commented Mar 28, 2020

I just tried it and it worked for me though. And it's clearly a bug. I'm going to go ahead and make the change that @kglassmire suggests.

@kglassmireacr
Copy link

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
Copy link
Collaborator

AArnott commented Mar 30, 2020

It works on Ubuntu 19.10, at least for me in a Docker container. I haven't tried 19.04.

@kglassmireacr
Copy link

Yeah just to follow-up on your comment @AArnott -- It's not working on regular Ubuntu 19.10 for me inside VS Code (not Lubuntu). I have a VM of that sitting around, too and set the test up on there.

It does not affect just building via dotnet cli if that is how you're testing -- this still works splendidly. Not sure if you're just invoking dotnet build or something in a Docker container. This is very Omnisharp specific it seems. I have seen some threads in the past regarding this underlying lib2gitsharp stuff and saw some mention of how RIDs are resolved for different Linux distributions (even varying by version) so maybe that's where this is happening.

It's inside of VS Code when Omnisharp is initializing the C# plug-in when a C# project is opened in VS Code.

The way I was testing this across all the OSes I was trying was:

  1. Clone a repo that already had NBGV 3.0.50 present in Directory.Build.props onto Ubuntu (whichever version)
  2. As soon as it opens up, go look at the OmniSharp logs -- it will also give you the prompt on the bottom right saying "some projects have trouble loading. See the output window for more details"
  3. Go into OmniSharp Log output window, you see the message similar to the top-level description of this GitHub issue
  4. Go into Directory.Build.props, update to 3.1.74
  5. Run dotnet build or, at a minimum, dotnet restore
  6. This typically makes the OmniSharp plug-in reload anyway but if it doesn't see step 7
  7. with the VS Code command palette, select the OmniSharp: Restart Omnisharp task
  8. Depending on the OS it is either still broken with the same message as the top-level description in this GitHub issue or everything is fine and Intellisense is working. If broken, the message is like above (this is taken from Ubuntu 19.10:
Starting OmniSharp server at 3/30/2020, 12:01:38 AM
    Target: /home/kglassmire/test-nbgv-upgrade/Test-Nbgv-Update.sln

OmniSharp server started.
    Path: /home/kglassmire/.vscode/extensions/ms-dotnettools.csharp-1.21.15/.omnisharp/1.34.14/run
    PID: 3555

[info]: OmniSharp.Stdio.Host
        Starting OmniSharp on ubuntu 19.10 (x64)
[info]: OmniSharp.Services.DotNetCliService
        DotNetPath set to dotnet
[info]: OmniSharp.MSBuild.Discovery.MSBuildLocator
        Located 1 MSBuild instance(s)
            1: StandAlone 16.4 - "/home/kglassmire/.vscode/extensions/ms-dotnettools.csharp-1.21.15/.omnisharp/1.34.14/omnisharp/.msbuild/Current/Bin"
[info]: OmniSharp.MSBuild.Discovery.MSBuildLocator
        MSBUILD_EXE_PATH environment variable set to '/home/kglassmire/.vscode/extensions/ms-dotnettools.csharp-1.21.15/.omnisharp/1.34.14/omnisharp/.msbuild/Current/Bin/MSBuild.dll'
[info]: OmniSharp.MSBuild.Discovery.MSBuildLocator
        Registered MSBuild instance: StandAlone 16.4 - "/home/kglassmire/.vscode/extensions/ms-dotnettools.csharp-1.21.15/.omnisharp/1.34.14/omnisharp/.msbuild/Current/Bin"
            CscToolExe = csc.exe
            MSBuildToolsPath = /home/kglassmire/.vscode/extensions/ms-dotnettools.csharp-1.21.15/.omnisharp/1.34.14/omnisharp/.msbuild/Current/Bin
            CscToolPath = /home/kglassmire/.vscode/extensions/ms-dotnettools.csharp-1.21.15/.omnisharp/1.34.14/omnisharp/.msbuild/Current/Bin/Roslyn
            BypassFrameworkInstallChecks = true
            MSBuildExtensionsPath = /home/kglassmire/.vscode/extensions/ms-dotnettools.csharp-1.21.15/.omnisharp/1.34.14/omnisharp/.msbuild
[info]: OmniSharp.Cake.CakeProjectSystem
        Detecting Cake files in '/home/kglassmire/test-nbgv-upgrade'.
[info]: OmniSharp.Cake.CakeProjectSystem
        Could not find any Cake files
[info]: OmniSharp.MSBuild.ProjectSystem
        Detecting projects in '/home/kglassmire/test-nbgv-upgrade/Test-Nbgv-Update.sln'.
[info]: OmniSharp.MSBuild.ProjectManager
        Queue project update for '/home/kglassmire/test-nbgv-upgrade/Test-Nbgv-Update/Test-Nbgv-Update.csproj'
[info]: OmniSharp.Script.ScriptProjectSystem
        Detecting CSX files in '/home/kglassmire/test-nbgv-upgrade'.
[info]: OmniSharp.Script.ScriptProjectSystem
        Could not find any CSX files
[info]: OmniSharp.WorkspaceInitializer
        Invoking Workspace Options Provider: OmniSharp.Roslyn.CSharp.Services.CSharpFormattingWorkspaceOptionsProvider, Order: 0
[info]: OmniSharp.MSBuild.ProjectManager
        Loading project: /home/kglassmire/test-nbgv-upgrade/Test-Nbgv-Update/Test-Nbgv-Update.csproj
[info]: OmniSharp.WorkspaceInitializer
        Invoking Workspace Options Provider: OmniSharp.Roslyn.CSharp.Services.RenameWorkspaceOptionsProvider, Order: 100
[info]: OmniSharp.WorkspaceInitializer
        Invoking Workspace Options Provider: OmniSharp.Roslyn.CSharp.Services.ImplementTypeWorkspaceOptionsProvider, Order: 110
[info]: OmniSharp.WorkspaceInitializer
        Invoking Workspace Options Provider: OmniSharp.Roslyn.CSharp.Services.EditorConfigWorkspaceOptionsProvider, Order: 200
[info]: OmniSharp.WorkspaceInitializer
        Configuration finished.
[info]: OmniSharp.Stdio.Host
        Omnisharp server running using Stdio at location '/home/kglassmire/test-nbgv-upgrade' on host 2616.
[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-106a5f2.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 <c6ddab362adb4977b9e6460e3b7d98f1>:0 
  at LibGit2Sharp.Core.NativeMethods..cctor () [0x00045] in <c6ddab362adb4977b9e6460e3b7d98f1>: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 <c6ddab362adb4977b9e6460e3b7d98f1>:0 
  at LibGit2Sharp.GlobalSettings.SetConfigSearchPaths (LibGit2Sharp.ConfigurationLevel level, System.String[] paths) [0x0001a] in <c6ddab362adb4977b9e6460e3b7d98f1>:0 
  at Nerdbank.GitVersioning.GitExtensions.OpenGitRepo (System.String pathUnderGitRepo, System.Boolean useDefaultConfigSearchPaths) [0x00025] in <7eb9cc81b7124404b676e58c10f1542c>: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 <7eb9cc81b7124404b676e58c10f1542c>:0 
  at Nerdbank.GitVersioning.Tasks.GetBuildVersion.ExecuteInner () [0x000c5] in <c7bbab3e22eb4bcd8b0b70e37753891a>:0 
  at MSBuildExtensionTask.ContextAwareTask.Execute () [0x0005e] in <c7bbab3e22eb4bcd8b0b70e37753891a>:0 
  at Microsoft.Build.BackEnd.TaskExecutionHost.Microsoft.Build.BackEnd.ITaskExecutionHost.Execute () [0x00029] in <d7593966a5ec48e0baa47768c52e35a5>: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 <d7593966a5ec48e0baa47768c52e35a5>:0 
[warn]: OmniSharp.MSBuild.ProjectManager
        Failed to load project file '/home/kglassmire/test-nbgv-upgrade/Test-Nbgv-Update/Test-Nbgv-Update.csproj'.
/home/kglassmire/test-nbgv-upgrade/Test-Nbgv-Update/Test-Nbgv-Update.csproj
/home/kglassmire/.nuget/packages/nerdbank.gitversioning/3.1.74/build/Nerdbank.GitVersioning.targets(71,5): Error: 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-106a5f2.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 <c6ddab362adb4977b9e6460e3b7d98f1>:0 
  at LibGit2Sharp.Core.NativeMethods..cctor () [0x00045] in <c6ddab362adb4977b9e6460e3b7d98f1>: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 <c6ddab362adb4977b9e6460e3b7d98f1>:0 
  at LibGit2Sharp.GlobalSettings.SetConfigSearchPaths (LibGit2Sharp.ConfigurationLevel level, System.String[] paths) [0x0001a] in <c6ddab362adb4977b9e6460e3b7d98f1>:0 
  at Nerdbank.GitVersioning.GitExtensions.OpenGitRepo (System.String pathUnderGitRepo, System.Boolean useDefaultConfigSearchPaths) [0x00025] in <7eb9cc81b7124404b676e58c10f1542c>: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 <7eb9cc81b7124404b676e58c10f1542c>:0 
  at Nerdbank.GitVersioning.Tasks.GetBuildVersion.ExecuteInner () [0x000c5] in <c7bbab3e22eb4bcd8b0b70e37753891a>:0 
  at MSBuildExtensionTask.ContextAwareTask.Execute () [0x0005e] in <c7bbab3e22eb4bcd8b0b70e37753891a>:0 
  at Microsoft.Build.BackEnd.TaskExecutionHost.Microsoft.Build.BackEnd.ITaskExecutionHost.Execute () [0x00029] in <d7593966a5ec48e0baa47768c52e35a5>: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 <d7593966a5ec48e0baa47768c52e35a5>:0 

[fail]: OmniSharp.MSBuild.ProjectManager
        Attempted to update project that is not loaded: /home/kglassmire/test-nbgv-upgrade/Test-Nbgv-Update/Test-Nbgv-Update.csproj

All this being said, the fact that it works on Ubuntu 18.04 is probably good enough for most and I am appreciative you even got that working as I imagine supporting these different distros because of libssl is probably excessively time-consuming. I know you said that eventually these package bundles for libssl might not even be necessary after they finish some stuff on libssl's side so I am content with an 18.04 fix as I primarily use Ubuntu VMs to debug Docker containers.

@AArnott
Copy link
Collaborator

AArnott commented Mar 30, 2020

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.

@Meligy
Copy link

Meligy commented Apr 27, 2020

I think I'm seeing this with v3.1.74 still.

Is this supposed to be working? Or is there a workaround?

My case is running a solution in a VS Code Dev Containers, the standard C# (.NET Core 3.1) one, with no changes.

This is how their stock Dockerfile looks like BTW:

#-------------------------------------------------------------------------------------------------------------
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License. See https://go.microsoft.com/fwlink/?linkid=2090316 for license information.
#-------------------------------------------------------------------------------------------------------------

FROM mcr.microsoft.com/dotnet/core/sdk:3.1

# This Dockerfile adds a non-root user with sudo access. Use the "remoteUser"
# property in devcontainer.json to use it. On Linux, the container user's GID/UIDs
# will be updated to match your local UID/GID (when using the dockerFile property).
# See https://aka.ms/vscode-remote/containers/non-root-user for details.
ARG USERNAME=vscode
ARG USER_UID=1000
ARG USER_GID=$USER_UID

# [Optional] Version of Node.js to install.
ARG INSTALL_NODE="true"
ARG NODE_VERSION="lts/*"
ENV NVM_DIR=/home/vscode/.nvm

# [Optional] Install the Azure CLI
ARG INSTALL_AZURE_CLI="false"

# Avoid warnings by switching to noninteractive
ENV DEBIAN_FRONTEND=noninteractive

# Configure apt and install packages
RUN apt-get update \
    && apt-get -y install --no-install-recommends apt-utils dialog 2>&1 \
    #
    # Verify git, process tools, lsb-release (common in install instructions for CLIs) installed
    && apt-get -y install git openssh-client less iproute2 procps apt-transport-https gnupg2 curl lsb-release \
    #
    # Create a non-root user to use if preferred - see https://aka.ms/vscode-remote/containers/non-root-user.
    && groupadd --gid $USER_GID $USERNAME \
    && useradd -s /bin/bash --uid $USER_UID --gid $USER_GID -m $USERNAME \
    # [Optional] Add sudo support for the non-root user
    && apt-get install -y sudo \
    && echo $USERNAME ALL=\(root\) NOPASSWD:ALL > /etc/sudoers.d/$USERNAME\
    && chmod 0440 /etc/sudoers.d/$USERNAME \
    #
    # [Optional] Install Node.js for ASP.NET Core Web Applicationss
    && if [ "$INSTALL_NODE" = "true" ]; then \
    #
    # Install nvm and Node
    mkdir ${NVM_DIR} \
    && curl -so- https://raw.githubusercontent.com/creationix/nvm/v0.34.0/install.sh | bash 2>&1 \
    && chown -R vscode:vscode ${NVM_DIR} \
    && /bin/bash -c "source $NVM_DIR/nvm.sh \
    && nvm install ${NODE_VERSION} \
    && nvm alias default ${NODE_VERSION}" 2>&1 \
    && INIT_STRING='[ -s "$NVM_DIR/nvm.sh" ] && \\. "$NVM_DIR/nvm.sh"  && [ -s "$NVM_DIR/bash_completion" ] && \\. "$NVM_DIR/bash_completion"' \
    && echo $INIT_STRING >> /home/vscode/.bashrc \
    && echo $INIT_STRING >> /home/vscode/.zshrc \
    && echo $INIT_STRING >> /root/.zshrc \
    #
    # Install yarn
    && curl -sS https://dl.yarnpkg.com/$(lsb_release -is | tr '[:upper:]' '[:lower:]')/pubkey.gpg | apt-key add - 2>/dev/null \
    && echo "deb https://dl.yarnpkg.com/$(lsb_release -is | tr '[:upper:]' '[:lower:]')/ stable main" | tee /etc/apt/sources.list.d/yarn.list \
    && apt-get update \
    && apt-get -y install --no-install-recommends yarn; \
    fi \
    #
    # [Optional] Install the Azure CLI
    && if [ "$INSTALL_AZURE_CLI" = "true" ]; then \
    echo "deb [arch=amd64] https://packages.microsoft.com/repos/azure-cli/ $(lsb_release -cs) main" > /etc/apt/sources.list.d/azure-cli.list \
    && curl -sL https://packages.microsoft.com/keys/microsoft.asc | apt-key add - 2>/dev/null \
    && apt-get update \
    && apt-get install -y azure-cli; \
    fi \
    #
    # Clean up
    && apt-get autoremove -y \
    && apt-get clean -y \
    && rm -rf /var/lib/apt/lists/*

# Switch back to dialog for any ad-hoc use of apt-get
ENV DEBIAN_FRONTEND=dialog

The .NET Core image is using Debian 10, in case it makes a difference.

@AArnott
Copy link
Collaborator

AArnott commented Apr 28, 2020

@Meligy Please open a new issue. NB.GV's dependency on libgit2sharp, which transitively depends on libssl, means that each linux distribution needs attention to work. This issue is about Ubuntu while your issue is about Debian 10.

@gxtaillon
Copy link

Coming from google, on debian 10, the fix from #482 (comment) works wonders.

@reinaldocoelho
Copy link

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!

@AArnott AArnott added this to the v3.1 milestone Dec 24, 2020
@AArnott
Copy link
Collaborator

AArnott commented Dec 24, 2020

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

@reinaldocoelho
Copy link

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

@reinaldocoelho
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.