Skip to content

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

Description

@Standret

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

Activity

  1. montague247 commented on Aug 18, 2019

    @montague247

    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

  2. Standret commented on Aug 20, 2019

    @Standret
    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>
    
    
  3. toanxyz commented on Oct 2, 2019

    @toanxyz

    I have the same issue too when running in Azure Functions

  4. AleksandrSor commented on Nov 30, 2019

    @AleksandrSor

    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)

  5. jayakumarj85 commented on Dec 10, 2019

    @jayakumarj85

    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.

  6. matilote commented on Dec 18, 2019

    @matilote

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

  7. xJonathanLEI commented on Dec 31, 2019

    @xJonathanLEI

    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.

  8. nZeus commented on Jan 2, 2020

    @nZeus

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

  9. paulostradioti commented on Feb 19, 2020

    @paulostradioti

    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

  10. ahmedhammad97 commented on Feb 29, 2020

    @ahmedhammad97

    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.

  11. trondhindenes commented on Mar 14, 2020

    @trondhindenes

    Try using Ubuntu 18.04

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

  12. bording commented on Mar 14, 2020

    @bording
    Member

    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.

  13. patrolez commented on Mar 31, 2020

    @patrolez

    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)

  14. capraynor commented on Apr 26, 2020

    @capraynor

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

  15. tjmoore commented on Sep 4, 2020

    @tjmoore

    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

  16. 8 remaining items

  17. bording commented on Mar 4, 2021

    @bording
    Member

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

  18. csurfleet commented on Sep 8, 2021

    @csurfleet

    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?

  19. bording commented on Sep 8, 2021

    @bording
    Member

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

  20. dradovic commented on Sep 23, 2021

    @dradovic

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

  21. aziz-shahed-cko commented on Oct 13, 2021

    @aziz-shahed-cko

    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

  22. jayakumarj85 commented on Oct 29, 2021

    @jayakumarj85

    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

  23. Eternal21 commented on Dec 25, 2022

    @Eternal21

    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>
  24. MahdiKarimipour commented on Feb 6, 2023

    @MahdiKarimipour

    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.

  25. OskiKervinen-MF commented on Feb 14, 2023

    @OskiKervinen-MF

    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.

  26. arrowd commented on Jun 2, 2025

    @arrowd

    I'm now building libgit2sharp on FreeBSD and also getting this error for obvious reason.

    I'm actually surprised that libgit2sharp tries to ship all the possible variants of the native library rather than having an option to use (or at least to fallback to) a system libgit2.so coming from the OS package manager.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions