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

Unable to load shared library 'git2-7ce88e6' or one of its dependencies. #1703

Closed
Standret opened this issue Aug 16, 2019 · 29 comments
Closed

Comments

@Standret
Copy link

Hi there,

So I've encountered with a quite strange problem when I tried to run my program on ubuntu. As you can see in the log below the app crashes each time when trying to invoke any method from libgit, and it is quite strange cause this project works on Windows10 perfectly.

The type initializer for 'LibGit2Sharp.Core.NativeMethods' threw an exception.
   at LibGit2Sharp.Core.NativeMethods.git_clone(git_repository*& repo, String origin_url, FilePath workdir_path, GitCloneOptions& opts)
   at LibGit2Sharp.Core.Proxy.git_clone(String url, String workdir, GitCloneOptions& opts) in C:\projects\libgit2sharp\LibGit2Sharp\Core\Proxy.cs:line 275
   at LibGit2Sharp.Repository.Clone(String sourceUrl, String workdirPath, CloneOptions options) in C:\projects\libgit2sharp\LibGit2Sharp\Repository.cs:line 779
   at Stt.GitSync.Infrastructure.Managers.RepositoriesManager.CloneIfNotExists(ConfigurationData data) in /home/grimm/Documents/SE/C#/SttGitSync/Stt.GitSync/Infrastructure/Managers/RepositoriesManager.cs:line 96

Unable to load shared library 'git2-7ce88e6' or one of its dependencies. In order to help diagnose loading problems, consider setting the LD_DEBUG environment variable: libgit2-7ce88e6: cannot open shared object file: No such file or directory
   at LibGit2Sharp.Core.NativeMethods.git_libgit2_init()
   at LibGit2Sharp.Core.NativeMethods.InitializeNativeLibrary() in C:\projects\libgit2sharp\LibGit2Sharp\Core\NativeMethods.cs:line 78
   at LibGit2Sharp.Core.NativeMethods..cctor() in C:\projects\libgit2sharp\LibGit2Sharp\Core\NativeMethods.cs:line 56

Reproduction steps

Try to use any LibGit2 method and you get this error

Expected behavior

Repository is cloned

Actual behavior

Exception is raised

Version of LibGit2Sharp (release number or SHA1)

<PackageReference Include="LibGit2Sharp" Version="0.26.1" />
<PackageReference Include="LibGit2Sharp.NativeBinaries" Version="2.0.289" />

Operating system(s) tested; .NET runtime tested

ubuntu 19.04
netcoreapp2.2

@montague247
Copy link

Hi,

the same issue on my Mac.
10.14.5 (18F132) (Mojave)

On windows everything works fine.

Rolling back to 0.26.0 works.

Best regards

@Standret
Copy link
Author

Hmm, I've tried to create the empty project which just clones the public repository. and this error occurs again and again, and the version of libgit does not matter. I've also attached my .csproj, probably I've done something wrong.

<Project Sdk="Microsoft.NET.Sdk">

  <PropertyGroup>
    <OutputType>Exe</OutputType>
    <TargetFramework>netcoreapp2.2</TargetFramework>
  </PropertyGroup>

  <ItemGroup>
    <PackageReference Include="LibGit2Sharp" Version="0.26.0" />
    <PackageReference Include="Newtonsoft.Json" Version="12.0.1" />
    <PackageReference Include="System.Reactive" Version="4.1.3" />
  </ItemGroup>

</Project>

@toanxyz
Copy link

toanxyz commented Oct 2, 2019

I have the same issue too when running in Azure Functions

@AleksandrSor
Copy link

Apparently, lib2git cant find correct native binaries so I helped it with this trick
I had all needed binaries in /app/runtimes/ so i added env variable into my Dockerfile
like this

FROM base AS final

ENV LD_LIBRARY_PATH=/app/runtimes/debian.9-x64/native/

work for dotnet core 3.0 (aspnet:3.0-buster-slim)

@jayakumarj85
Copy link

As of now libgit2sharp provides the native libraries for the following linux distributions,
win-x86
win-x64
win-arm64
win
unix
ubuntu.18.04-x64
ubuntu.16.04-arm64
rhel-x64
osx
linux-x64
fedora-x64
debian.9-x64
debian-arm64
alpine.3.9-x64
alpine-x64

In such case using ubuntu 19.04 is not going to work. Try using Ubuntu 18.04 and see if it works.

Otherwise try switching to any of the above mentioned linux distributions.

@matilote
Copy link

matilote commented Dec 18, 2019

/root/.nuget/packages/gitversiontask/5.1.2/build/GitVersionTask.targets(10,9): error : PlatformNotSupportedException: debian.9-arm64
Tried different arm64 distributions with no luck.

@xJonathanLEI
Copy link

Encountered the same issue when running in Docker. Changed my runtime from:

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

to

FROM mcr.microsoft.com/dotnet/core/aspnet:3.1-bionic

solves the problem.

@nZeus
Copy link

nZeus commented Jan 2, 2020

I tried mcr.microsoft.com/dotnet/core/sdk:3.1-bionic and it works! 🎉

@paulostradioti
Copy link

paulostradioti commented Feb 19, 2020

For me, it worked with mcr.microsoft.com/dotnet/core/sdk:3.1-alpine and mcr.microsoft.com/dotnet/core/runtime:3.1-alpine.

Thanks

@ahmedhammad97
Copy link

Looks like the problem is that the binary git2-7ce88e6 is built to the wrong directory, so the program is not able to load it when it look for it in the right one.

What worked for me was adding an MSBuild PostBuildEvent to .csproj which copies the git2-7ce88e6 binary from the directory it was built, to the directory it is expected to run from.
These directories might differ, so it is better to check them manually.

@trondhindenes
Copy link

Try using Ubuntu 18.04

this is becoming a problem. Is there any plan to support newer ubuntu versions than 18.x?

@bording
Copy link
Member

bording commented Mar 14, 2020

this is becoming a problem. Is there any plan to support newer ubuntu versions than 18.x?

It's not really sustainable to be constantly chasing support for newer platforms for a number of reasons. There needs to be a native binary compiled to match the versions of the dependencies on the distro.

There are plans to sidestep the entire problem by removing as many dependencies as possible from the native binary, enabling a single linux binary to work with most/all distros.

The biggest piece of work remaining to enable this is #1618.

@patrolez
Copy link

patrolez commented Mar 31, 2020

Regarding newer Ubuntu:
#1714 (comment)

The most latest NuGet release 0.27-preview works correctly.

The reason is that since Ubuntu Eoan OpenSSL 1.0 was completely removed from shipping within distro.
The same is about the newest Debian.

Shipping a libgit2 linked against OpenSSL 1.1 does the work.
#1747 (comment)

@capraynor
Copy link

Same issue here. This library won't work on Azure app service, Linux.
Doing the following settings can solve this issue:
image

@tjmoore
Copy link

tjmoore commented Sep 4, 2020

Raspbian buster (Debian 10 based) has the same Unable to load shared library 'git2-7ce88e6'

I'm using Nuke to build and it's failing on GitVersion which is using LibGit2Shap.

To be fair, building on a Raspberry Pi is not practical. Much better to cross compile for ARM. It was just curiosity really. Though it does mean I can't use GitVersion from the command line on the pi either. GitTools/GitVersion#2260

@gitfool
Copy link

gitfool commented Sep 6, 2020

@tjmoore I use Cake and GitVersion, which is a similar setup. You should be able to get it to work by pre-installing GitVersion and patching LD_LIBRARY_PATH, before calling Nuke, with a variant of @AleksandrSor's workaround.

See gitfool/Cake.Dungeon@0655e23 for my workaround for the GitLab shared Linux runners which are now based on Debian 10.

collinbarrett added a commit to collinbarrett/FilterLists that referenced this issue Sep 22, 2020
@jessicah
Copy link

jessicah commented Nov 2, 2020

Official .NET 5.0 Docker images are using Debian 10 now, so it'd be nice to see that added to the list of supported platforms. The LD_LIBRARY_PATH hack does work though...

markwhitaker added a commit to markwhitaker/RegexToolbox.NET that referenced this issue Jan 2, 2021
Getting errors with LibGit2Sharp and this suggested it doesn't support beyond 18.04: libgit2/libgit2sharp#1703 (comment)
markwhitaker added a commit to markwhitaker/RegexToolbox.NET that referenced this issue Jan 2, 2021
Getting errors with LibGit2Sharp and this suggested it doesn't support beyond 18.04: libgit2/libgit2sharp#1703 (comment)
@bigpod98
Copy link

cmon fix this

@bording
Copy link
Member

bording commented Jan 26, 2021

@bigpod98 This should be fixed with the latest preview release.

@bigpod98
Copy link

@bording after i vented my frustration i looked at other issues a bit closly and i found that i should use preview release and it worksy was just about to remove my frustrated comment

@bording
Copy link
Member

bording commented Mar 4, 2021

Since the latest preview release should have fixed this, I'm going to go ahead and close it.

@bording bording closed this as completed Mar 4, 2021
MaxAtoms added a commit to MaxAtoms/RepoStatusTable that referenced this issue Jul 21, 2021
The current stable version of LibGit2Sharp (0.26.2) does not work on Linux.
The latest preview version runs without any issues.

See: libgit2/libgit2sharp#1703 (comment)
MaxAtoms added a commit to MaxAtoms/RepoStatusTable that referenced this issue Aug 14, 2021
The current stable version of LibGit2Sharp (0.26.2) does not work on Linux.
The latest preview version runs without any issues.

See: libgit2/libgit2sharp#1703 (comment)
@csurfleet
Copy link

I'm on the latest preview (0.27.0-preview-0007) and this is not working on aspnet:5.0-buster-slim, which according to: https://hub.docker.com/_/microsoft-dotnet-aspnet is a debian 10 image. Could someone advise on the preview version/dotnet5 image combo I should be using please?

@bording
Copy link
Member

bording commented Sep 8, 2021

@csurfleet The latest preview version is 0.27.0-preview-0119, so give that a try.

@dradovic
Copy link

dradovic commented Sep 23, 2021

@bording I'm experiencing the same problem with 0.27.0-preview-0119 on the Bitbucket CI/CD infrastructure. Unfortunately, it's not appearing consistently (I guess it depends what actual build agent is chosen to build the solution). The error I'm seeing sporadically is:

System.TypeInitializationException : The type initializer for 'LibGit2Sharp.Core.NativeMethods' threw an exception.
---- System.DllNotFoundException : Unable to load shared library 'git2-8a0dc67' or one of its dependencies. In order to help diagnose loading problems, consider setting the LD_DEBUG environment variable: libgit2-8a0dc67: cannot open shared object file: No such file or directory

As this is a closed issue, I've opened #1914 for this.

@aziz-shahed-cko
Copy link

As of now libgit2sharp provides the native libraries for the following linux distributions, win-x86 win-x64 win-arm64 win unix ubuntu.18.04-x64 ubuntu.16.04-arm64 rhel-x64 osx linux-x64 fedora-x64 debian.9-x64 debian-arm64 alpine.3.9-x64 alpine-x64

In such case using ubuntu 19.04 is not going to work. Try using Ubuntu 18.04 and see if it works.

Otherwise try switching to any of the above mentioned linux distributions.

Where can I find this list?
I was able to make gitversion work using libssl1.1. But it does not work for Ubuntu 20.04.
If I could find the updated list for libgit2sharp , I could figure out which image I can use it with

@jayakumarj85
Copy link

As of now libgit2sharp provides the native libraries for the following linux distributions, win-x86 win-x64 win-arm64 win unix ubuntu.18.04-x64 ubuntu.16.04-arm64 rhel-x64 osx linux-x64 fedora-x64 debian.9-x64 debian-arm64 alpine.3.9-x64 alpine-x64
In such case using ubuntu 19.04 is not going to work. Try using Ubuntu 18.04 and see if it works.
Otherwise try switching to any of the above mentioned linux distributions.

Where can I find this list? I was able to make gitversion work using libssl1.1. But it does not work for Ubuntu 20.04. If I could find the updated list for libgit2sharp , I could figure out which image I can use it with

Way back in 2019 when I posted this answer, I was using LibGit2Sharp.NativeBinaries v2.0.289 and libgit2sharp was providing the native libraries for the distributions I have mentioned. You can look at the list here under runtimes directory in the following link https://nuget.info/packages/LibGit2Sharp.NativeBinaries/2.0.289

The latest version of libgit2sharp v0.27.0-preview-0119 has a dependency on LibGit2Sharp.NativeBinaries v2.0.315-alpha.0.1, the native libraries supported can be found here https://nuget.info/packages/LibGit2Sharp.NativeBinaries/2.0.315-alpha.0.1

If you are using libgit2sharp v0.26.2, then it has a dependency on LibGit2Sharp.NativeBinaries v2.0.306, the native libraries supported can be found here https://nuget.info/packages/LibGit2Sharp.NativeBinaries/2.0.306

brandonpbenson added a commit to brandonpbenson/RepoStatusTable that referenced this issue Feb 9, 2022
The current stable version of LibGit2Sharp (0.26.2) does not work on Linux.
The latest preview version runs without any issues.

See: libgit2/libgit2sharp#1703 (comment)
dylan-smith added a commit to github/gh-gei that referenced this issue Nov 23, 2022
<!--
For the checkboxes below you must check each one to indicate that you
either did the relevant task, or considered it and decided there was
nothing that needed doing
-->

Added code to do a similar thing we do with our other e2e tests, where
the test is responsible for resetting the test data that it expects in
the test environment. This makes it easy to stand up new environments,
and prevent accidentally breaking test environments by unintentional
manual changes in the BBS server(s). It also makes it easy to add new
data shapes to our test environments, as we just add them in one place
(in the code) rather than having to manually touch each of our BBS test
servers (and we will have several of them before we're done with the BBS
work).

Right now these additions will check if the BBS project exists, and if
so iterate and delete all repos in the project, then delete the project.
Then create the project(s) and repo(s) from scratch.

It uses libgit2sharp to initialize the repos. This dependency only
exists in our e2e test code, not in the CLI that we ship to customers.
libgit2sharp comes with native binaries for various linux distro's, but
only includes ubuntu 18.04 but our build servers use ubuntu 20.04 (or
maybe 22.04). The workaround is to use the LD_LIBRARY_PATH env var when
building our integration test project to force it to link to the ubuntu
18.04 binary
(libgit2/libgit2sharp#1703 (comment))

This has pretty much everything we need to support testing against BBS
5.14 also (#570 ) except for some reason the initialize repo code fails
consistently when run against BBS 5.14. Once somebody figures out why
that fails, you just need to add an extra [InlineData] attribute to the
test case and it will run for both.

Closes #573 

- [x] Did you write/update appropriate tests
- [x] Release notes updated (if appropriate)
- [x] Appropriate logging output
- [x] Issue linked
- [x] Docs updated (or issue created)

<!--
For docs we should review the docs at:

https://docs.github.com/en/early-access/github/migrating-with-github-enterprise-importer
and the README.md in this repo

If a doc update is required based on the changes in this PR, it is
sufficient to create an issue and link to it here. The doc update can be
made later/separately.

The process to update the docs can be found here:
https://github.com/github/docs-early-access#opening-prs

The markdown files are here: 

https://github.com/github/docs-early-access/tree/main/content/github/migrating-with-github-enterprise-importer
-->
@Eternal21
Copy link

Eternal21 commented Dec 25, 2022

Hitting the same problem trying to run LibGit2Sharp in AWS lambda

EDIT: Managed to hack around the issue based on advice from these two comments:
aws/aws-lambda-dotnet#716 (comment)

...That is, I believe that the linux-x64 runtime libgit2-ef5a385.so is incompatible with AWS Linux. On the other hand, the rhel-x64 runtime works.

#1823 (comment)

The rhel-x64 runtime version of libgit2-ef5a385.so works on Amazon Linux 2.

The libgit2-106a5f2.so included with .NET 6 runtime, does not work with AWS. The workaround is to replace the published libgit2-106a5f2.so with the rhel-64/native one, located in: .nuget\packages\libgit2sharp.nativebinaries\2.0.306\runtimes\rhel-x64\native

You need to replace the so after the project is published, but obviously before you zip it and upload it to AWS. Again based on the above comment I used the following msbuild code for .NET 6 (edit your ...Lambda.csjproj file):

<Project>
   ...
    <Target Name="GitLib2SharpFix" AfterTargets="Publish">
        <!--See: https://github.com/libgit2/libgit2sharp/issues/1703#issuecomment-1364750879 -->
        <Exec Command="copy &quot;$(ProjectDir)bin\Release\net6.0\runtimes\rhel-x64\native\libgit2-106a5f2.so&quot; &quot;bin\Release\net6.0\publish\libgit2-106a5f2.so&quot;"/>
    </Target>
</Project>

@MahdiKarimipour
Copy link

0.27.0-preview

Upgrading to the preview fixed the "Unable to load shared library 'git2-106a5f2' or one of its dependencies"

As I was on alpine, it gave me another error that it is unable to load ssl/open ssl libraries, which I suspect is because alpine is lightweight. I switched to focal version and that fixed the ssl problem too.

@OskiKervinen-MF
Copy link

I found a work around for this, when using the dotnet:sdk6.0-alpine image. I used strace to determine it was loading the library from /app/runtimes/alpine.3.9-x64/native/libgit2-106a5f2.so. So I installed libgit2 from apk and overrode that file with the system version. This is what it looks like in a Dockerfile:

FROM mcr.microsoft.com/dotnet/sdk:6.0-alpine

RUN apk add git libgit2
COPY my_app/bin/Release/net6/publish/ /app/
RUN cp /usr/lib/libgit2.so.1.5 /app/runtimes/alpine.3.9-x64/native/libgit2-106a5f2.so

I would expect this sort of approach to work for any base image that can install a system libgit2, since the system libgit2 will be compatible with the system, while the native-managed invocations won't be tightly coupled, meaning the precise version of libgit2 isn't relevant to LibGit2Sharp, as long as all the entry points it calls are present.

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

No branches or pull requests