Repository navigation
System.DllNotFoundException: lib/linux/x86_64/libgit2-1196807.so on Ubuntu Linux #1585
Copy link
Copy link
Open
Description
I have difficulties with LibGit2Sharp while running Cake (with Cake.Git addin) build on Linux Ubuntu 16.04 in Docker - cake-contrib/Cake_Git#68
But I managed to isolate issue with LibGit2Sharp only.
Reproduction steps
touch gt.cs
using LibGit2Sharp;
using System;
public class Program
{
public static void Main()
{
Console.WriteLine("HI");
var repo = new Repository("/opt/buildagent/work/e1fb3d71588668ec");
}
}csc gt.cs /r:LibGit2Sharp.dll
mono gt.exe
HI
Unhandled Exception:
System.TypeInitializationException: The type initializer for 'LibGit2Sharp.Core.NativeMethods' threw an exception. ---> System.DllNotFoundException: lib/linux/x86_64/libgit2-1196807.so
at (wrapper managed-to-native) LibGit2Sharp.Core.NativeMethods.git_libgit2_init()
at LibGit2Sharp.Core.NativeMethods+LibraryLifetimeObject..ctor () [0x00006] in <c31a5a5a3e0a424683609ecf6c55de77>:0
at LibGit2Sharp.Core.NativeMethods..cctor () [0x00054] in <c31a5a5a3e0a424683609ecf6c55de77>:0
--- End of inner exception stack trace ---
at LibGit2Sharp.Core.Proxy.git_repository_open (System.String path) [0x00008] in <c31a5a5a3e0a424683609ecf6c55de77>:0
at LibGit2Sharp.Repository..ctor (System.String path, LibGit2Sharp.RepositoryOptions options, LibGit2Sharp.Repository+RepositoryRequiredParameter requiredParameter) [0x00312] in <c31a5a5a3e0a424683609ecf6c55de77>:0
at LibGit2Sharp.Repository..ctor (System.String path) [0x00000] in <c31a5a5a3e0a424683609ecf6c55de77>:0
at Program.Main () [0x0000c] in <f40fe756e0ec4a4d9aed452251bd0a53>:0
[ERROR] FATAL UNHANDLED EXCEPTION: System.TypeInitializationException: The type initializer for 'LibGit2Sharp.Core.NativeMethods' threw an exception. ---> System.DllNotFoundException: lib/linux/x86_64/libgit2-1196807.so
at (wrapper managed-to-native) LibGit2Sharp.Core.NativeMethods.git_libgit2_init()
at LibGit2Sharp.Core.NativeMethods+LibraryLifetimeObject..ctor () [0x00006] in <c31a5a5a3e0a424683609ecf6c55de77>:0
at LibGit2Sharp.Core.NativeMethods..cctor () [0x00054] in <c31a5a5a3e0a424683609ecf6c55de77>:0
--- End of inner exception stack trace ---
at LibGit2Sharp.Core.Proxy.git_repository_open (System.String path) [0x00008] in <c31a5a5a3e0a424683609ecf6c55de77>:0
at LibGit2Sharp.Repository..ctor (System.String path, LibGit2Sharp.RepositoryOptions options, LibGit2Sharp.Repository+RepositoryRequiredParameter requiredParameter) [0x00312] in <c31a5a5a3e0a424683609ecf6c55de77>:0
at LibGit2Sharp.Repository..ctor (System.String path) [0x00000] in <c31a5a5a3e0a424683609ecf6c55de77>:0
at Program.Main () [0x0000c] in <f40fe756e0ec4a4d9aed452251bd0a53>:0
Mono looks up for native module in subfolder bacause of config
cat LibGit2Sharp.dll.config
<configuration>
<dllmap os="linux" cpu="x86-64" wordsize="64" dll="git2-1196807" target="lib/linux/x86_64/libgit2-1196807.so" />
<dllmap os="osx" cpu="x86,x86-64" dll="git2-1196807" target="lib/osx/libgit2-1196807.dylib" />
</configuration>the file lib/linux/x86_64/libgit2-1196807.so does exist. also tried to copy it besides my .exe module.
Expected behavior
no error
Actual behavior
System.TypeInitializationException: The type initializer for 'LibGit2Sharp.Core.NativeMethods' threw an exception. ---> System.DllNotFoundException: lib/linux/x86_64/libgit2-1196807.so
Version of LibGit2Sharp (release number or SHA1)
libgit2-1196807.so
Operating system(s) tested; .NET runtime tested
# cat /etc/os-release
NAME="Ubuntu"
VERSION="16.04.3 LTS (Xenial Xerus)"
ID=ubuntu
ID_LIKE=debian
PRETTY_NAME="Ubuntu 16.04.3 LTS"
VERSION_ID="16.04"
HOME_URL="http://www.ubuntu.com/"
SUPPORT_URL="http://help.ubuntu.com/"
BUG_REPORT_URL="http://bugs.launchpad.net/ubuntu/"
VERSION_CODENAME=xenial
UBUNTU_CODENAME=xenial
# mono --version
Mono JIT compiler version 5.12.0.226 (tarball Thu May 3 09:48:32 UTC 2018)
Copyright (C) 2002-2014 Novell, Inc, Xamarin Inc and Contributors. www.mono-project.com
TLS: __thread
SIGSEGV: altstack
Notifications: epoll
Architecture: amd64
Disabled: none
Misc: softdebug
Interpreter: yes
LLVM: supported, not enabled.
GC: sgen (concurrent by default)
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels
Activity
evil-shrike commentedon Jun 22, 2018
As a workaround for me worked this trick with installing libgit2-24 globally and setup its target path in
LibGit2Sharp.dll.config(as/usr/lib/x86_64-linux-gnu/libgit2.so.24). But as I'm using it via Cake/Cake.Git it's very hard to use this workaround.evil-shrike commentedon Jun 22, 2018
I seems I solved the issue by installing
apt-get isntall libc6 libcurl3. Not sure about the need oflibc6but after I installedlibcurl3libgit2sharp began working.That comment helps - #1472 (comment)
bording commentedon Jun 22, 2018
@evil-shrike curl is a requirement, so it sounds like you've fixed the problem!
evil-shrike commentedon Jun 22, 2018
@bording yeah, but may be it makes sense to put the required curl module besides libgit2-1196807.so? Or at least put some warning in Readme?
bording commentedon Jun 22, 2018
Attempting to bundle other libraries instead of linking against the system versions is not something we want to do, especially for something like OpenSSL.
Adding something to the README that lists all of the required native dependencies is a good idea!
ethomson commentedon Jun 23, 2018
We are not going to ship OpenSSL (which we would have to do, transitively), and you don’t want us to. If there are security holes in it, you want a single source of OpenSSL that you can patch. You want to know that you fixed all of them when you do. You don’t want some version that we installed still being vulnerable.
pauldotknopf commentedon Jun 24, 2018
I agree about openssl, but I think you should statically link libcurl. It is a problematic dependency that various greatly between Ubuntu versions and packages on Ubuntu.
I've had more trouble with libcurl than any other library, trying to find the "sweet spot" of configuration for my OS and docker images.
Kong/insomnia#878
pauldotknopf commentedon Jun 24, 2018
Also, the latest .NET Core 2.1.1 depends upon libcurl4.
As it stands, I don't think LibGit2Sharp.NativeBinaries currently work on the latest .NET Core.
Try to use it in the latest
microsoft/dotnet:2.1.1-runtime-bionicdocker image.pauldotknopf commentedon Jun 24, 2018
I rebuilt libgit2 using the latest .NET Core docker images.
This works. It is a lot more setup with my docker images, considering I know how to manually build libgit2 and put it in the right place, but it works now.
pauldotknopf commentedon Jun 24, 2018
I am building libgit2 as a part of my docker build now. This ensures the resulting binary is valid for the platform.
bording commentedon Jun 30, 2018
We are currently using the same native library for all versions of Ubuntu. If 18.04 has changed the version of curl it ships, then we'll have to build a specific version of the library for it and ship it in the native binaries package.
tzachshabtay commentedon Nov 12, 2018
This was reproduced on Debian 9 as well, so not just an Ubuntu issue.
bording commentedon Nov 12, 2018
The latest 0.26.0 preview release includes both an Ubuntu 18.04 and Debian 9 binary, so it should work.
magne commentedon Dec 13, 2018
The following seems to work just fine on Ubuntu 18.10. I've tested with GitVersion modified to use these versions.
bording commentedon Dec 13, 2018
@magne Do you have
libssl1.0.0installed via APT? I would expect you'd have to before 18.10 would work.magne commentedon Dec 13, 2018
Yes, libssl1.0.0 (and libssl1.1) is installed.
bording commentedon Dec 13, 2018
My understanding is that
libssl1.0.0is not installed by default on 18.10. Is that something you installed?magne commentedon Dec 13, 2018
As you can see when I try to remove libssl1.0.0, it's dependents include the .Net Core runtimes and the openssh client. These I have installed. But it also includes the snap daemon, and I belive that was present after the initial OS installation.
I've also tried to spin up the
ubuntu-minimal:bionicandubuntu-minimal:cosmicLXC images, and both of those include libssl1.0.0 by default.bording commentedon Dec 13, 2018
Thanks for the additional information!
That doesn't seem to line up with my initial testing, so it looks like I've got some more investigation to do.
However, if we can reasonably assume that
libssl1.0.0is installed on 18.04 & 18.10, then that definitely simplifies things.AdmiringWorm commentedon Apr 20, 2019
I got hit with this same problem of libgit2sharp not being able to load the native library (In my case, I had all dependencies needed for the library, but running on Arch Linux instead of Ubuntu. Which is probably not officially supported).
I was able to solve this by adding a new
dllmapin theLibGit2Sharp.dll.configconfig file to fallback to the system installedlibgit2.solibrary.I appended the following to the configuration file (without removing anything)
Hopefully this helps someone else coming across this issue with the same problem.
PulsarFX commentedon Dec 2, 2019
On debian 9 with v0.26.0 and libgit2sharp.nativebinaries.2.0.278 I needed to change from
nohwnd commentedon Aug 31, 2020
@maulwuff thanks, that helped me work around the issue (on WSL2 Ubuntu 20.04 .NETCore 3.1.401)