System.DllNotFoundException: lib/linux/x86_64/libgit2-1196807.so on Ubuntu Linux
See original GitHub issueI have difficulties with LibGit2Sharp while running Cake (with Cake.Git addin) build on Linux Ubuntu 16.04 in Docker - https://github.com/cake-contrib/Cake_Git/issues/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)
Issue Analytics
- State:
- Created 5 years ago
- Reactions:1
- Comments:22 (8 by maintainers)
Top Results From Across the Web
Self-Contained dotnet core on Ubuntu System. ...
SysInfo .Net Core: 1.0.1 libgit2sharp.portable: 0.24.10 Ubuntu: 16.04 Summary I'm attempting to create a self contained publish of a dotnet ...
Read more >MonoDevelop and libpjsipDll.so library on Ubuntu. System. ...
i am trying to use a dll for Linux called: libpjsipDll_v44.so I got it from here http://code.google.com/p/sipeksdk/downloads/list.
Read more >DllNotFoundException
This error means that mono was unable to locate a library that one of the classes you are trying to use needs. This...
Read more >Download Ubuntu Desktop
Download Ubuntu Desktop. The open-source desktop operating system that powers millions of PCs and laptops around the world. Find out more about Ubuntu's...
Read more >Ubuntu Core
Ubuntu Core is Ubuntu for IoT and embedded environments, optimised for security and reliable ota updates ... The operating system optimised for IoT...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
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
dllmap
in theLibGit2Sharp.dll.config
config file to fallback to the system installedlibgit2.so
library.I appended the following to the configuration file (without removing anything)
Hopefully this helps someone else coming across this issue with the same problem.
On debian 9 with v0.26.0 and libgit2sharp.nativebinaries.2.0.278 I needed to change from