libgit2 / libgit2sharp

Git + .NET = ❤
http://libgit2.github.com
MIT License
3.13k stars 879 forks source link

Unable to load shared library 'git2-106a5f2' or one of its dependencies. #1965

Closed vmamidala-conga closed 1 year ago

vmamidala-conga commented 2 years ago

You are opening a bug report against the LibGit2Sharp project: we use GitHub Issues for tracking bug reports and feature requests. If you have a question about an API or usage, please ask on StackOverflow: http://stackoverflow.com/questions/tagged/libgit2sharp.

Otherwise, to report a bug, please fill out the reproduction steps (below) and delete these introductory paragraphs. Thanks!

Reproduction steps

I have used mcr.microsoft.com/dotnet/aspnet:3.1-alpine image as base image in our dotnet service dockerfile.

Expected behavior

Actual behavior

Producing this error while calling a method in the service, System.AggregateException: One or more errors occurred. (The type initializer for 'LibGit2Sharp.Core.NativeMethods' threw an exception.) ---> System.TypeInitializationException: The type initializer for 'LibGit2Sharp.Core.NativeMethods' threw an exception. ---> System.DllNotFoundException: Unable to load shared library 'git2-106a5f2' or one of its dependencies. In order to help diagnose loading problems, consider setting the LD_DEBUG environment variable: Error loading shared library libgit2-106a5f2: No such file or directory at LibGit2Sharp.Core.NativeMethods.git_libgit2_init() at LibGit2Sharp.Core.NativeMethods.InitializeNativeLibrary() at LibGit2Sharp.Core.NativeMethods..cctor() --- End of inner exception stack trace --- 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) at LibGit2Sharp.Repository.Clone(String sourceUrl, String workdirPath, CloneOptions options)

Version of LibGit2Sharp (release number or SHA1)

git2-106a5f2

Operating system(s) tested; .NET runtime tested

alpine-3.15 & .NET runtime 3.1.2

I don't find any issue with alpine-3.14 base image, mcr.microsoft.com/dotnet/aspnet:3.1-alpine3.14

kereoz commented 2 years ago

This is happening to me on Fedora 36 when using FSI with: #r "nuget: LibGit2Sharp"

However, if I build the project (after installing the dependency through dotnet add package libgit2sharp), then there are no issues. I get the following dlls in my project as a result:

./bin/Debug/net6.0/runtimes/win-x64/native/git2-106a5f2.dll
./bin/Debug/net6.0/runtimes/win-x86/native/git2-106a5f2.dll

However, these are not native binaries:

$ file ./bin/Debug/net6.0/runtimes/win-x64/native/git2-106a5f2.dll
./bin/Debug/net6.0/runtimes/win-x64/native/git2-106a5f2.dll: PE32+ executable (DLL) (console) x86-64, for MS Windows

And therefore these won't load in FSI, I tried #r @./bin/Debug/net6.0/runtimes/win-x64/native/git2-106a5f2.dll and get:

error FS0229: Error opening binary file '/workspaces/social-code/fsgit/./bin/Debug/net6.0/runtimes/win-x64/native/git2-106a5f2.dll': /workspaces/social-code/fsgit/bin/Debug/net6.0/runtimes/win-x64/native/git2-106a5f2.dll: bad cli header, rva 0

tl;dr, I am unable to use it in .fsx scripts. Any suggestions welcome :).

kereoz commented 2 years ago

PS: the same behavior is reproducible when developing in a VSCode dev container (using the default container for F# development, i.e., https://github.com/microsoft/vscode-dev-containers/tree/v0.238.0/containers/dotnet-fsharp).

bording commented 1 year ago

LibGit2Sharp v0.27 has been released on nuget.org.

It has a lot of improvements around the native binaries, so these problems are likely resolved.

Feel free to open a new issue if not.