question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

LibGit2Sharp.Core.NativeMethods threw an exception.

See original GitHub issue

Describe the bug We use GitVersion task in multiple AzureDevOps pipelines - azure-pipelines.yaml. This tasks is now failing for all pipelines which use the latest ubuntu vmImage (ubuntu 20.04). The task is not failing on ubuntu 18.04 nor windows image.

The error looks similar to https://github.com/GitTools/GitVersion/issues/1852 which is marked as resolved in 5.3.2 version. However Azure DevOps uses 5.0.1 version.

Expected Behavior

GitVersion task should succeed.

- task: GitVersion@5
      inputs:
        runtime: 'core'
        configFilePath: '$(Build.SourcesDirectory)/gitversion.yaml'
        updateAssemblyInfo: true

Actual Behavior

GitVersion task fails with this error:

2021-03-03T14:42:26.2984494Z ##[section]Starting: GitVersion
2021-03-03T14:42:26.2991240Z ==============================================================================
2021-03-03T14:42:26.2991800Z Task         : GitVersion Task
2021-03-03T14:42:26.2992230Z Description  : Easy Semantic Versioning (http://semver.org) for projects using Git
2021-03-03T14:42:26.2992618Z Version      : 5.0.1
2021-03-03T14:42:26.2992939Z Author       : GitVersion Contributors
2021-03-03T14:42:26.2993362Z Help         : See the [documentation](http://gitversion.readthedocs.org/en/latest/) for help
2021-03-03T14:42:26.2993823Z ==============================================================================
2021-03-03T14:42:26.7808216Z [command]/usr/bin/dotnet /home/vsts/work/_tasks/GitVersion_e5983830-3f75-11e5-82ed-81492570a08e/5.0.1/core/GitVersion.dll /home/vsts/work/1/s /output buildserver /nofetch /config /home/vsts/work/1/s/gitversion.yaml /updateassemblyinfo true
2021-03-03T14:42:27.2296875Z INFO [03/03/21 14:42:27:22] Working directory: /home/vsts/work/1/s
2021-03-03T14:42:27.2300424Z INFO [03/03/21 14:42:27:22] IsDynamicGitRepository: False
2021-03-03T14:42:27.3013440Z ERROR [03/03/21 14:42:27:30] An unexpected error occurred:
2021-03-03T14:42:27.3019228Z System.TypeInitializationException: The type initializer for 'LibGit2Sharp.Core.NativeMethods' threw an exception. ---> System.DllNotFoundException: Unable to load shared library 'git2-572e4d8' or one of its dependencies. In order to help diagnose loading problems, consider setting the LD_DEBUG environment variable: libgit2-572e4d8: cannot open shared object file: No such file or directory
2021-03-03T14:42:27.3021340Z    at LibGit2Sharp.Core.NativeMethods.git_libgit2_init()
2021-03-03T14:42:27.3024434Z    at LibGit2Sharp.Core.NativeMethods.InitializeNativeLibrary()
2021-03-03T14:42:27.3025863Z    at LibGit2Sharp.Core.NativeMethods..cctor()
2021-03-03T14:42:27.3246234Z    --- End of inner exception stack trace ---
2021-03-03T14:42:27.3282834Z    at LibGit2Sharp.Core.NativeMethods.git_buf_dispose(GitBuf buf)
2021-03-03T14:42:27.3283601Z    at LibGit2Sharp.Core.Proxy.ConvertPath(Func`2 pathRetriever)
2021-03-03T14:42:27.3284179Z    at LibGit2Sharp.Repository.Discover(String startingPath)
2021-03-03T14:42:27.3284932Z    at GitVersion.GitPreparer.GetDotGitDirectory() in D:\a\1\s\src\GitVersionCore\GitPreparer.cs:line 148
2021-03-03T14:42:27.3285818Z    at GitVersion.GitPreparer.GetProjectRootDirectory() in D:\a\1\s\src\GitVersionCore\GitPreparer.cs:line 162
2021-03-03T14:42:27.3286711Z    at GitVersion.ConfigFileLocator.Verify(GitPreparer gitPreparer, IFileSystem fileSystem) in D:\a\1\s\src\GitVersionCore\Configuration\ConfigFileLocator.cs:line 57
2021-03-03T14:42:27.3287583Z    at GitVersion.Program.VerifyArgumentsAndRun() in D:\a\1\s\src\GitVersionExe\Program.cs:line 95
2021-03-03T14:42:27.3288145Z INFO [03/03/21 14:42:27:30] 
2021-03-03T14:42:27.3288715Z INFO [03/03/21 14:42:27:30] Attempting to show the current git graph (please include in issue): 
2021-03-03T14:42:27.3289335Z INFO [03/03/21 14:42:27:30] Showing max of 100 commits
2021-03-03T14:42:27.3289881Z INFO [03/03/21 14:42:27:22] Working directory: /home/vsts/work/1/s
2021-03-03T14:42:27.3290662Z INFO [03/03/21 14:42:27:22] IsDynamicGitRepository: False
2021-03-03T14:42:27.3291224Z ERROR [03/03/21 14:42:27:30] An unexpected error occurred:
2021-03-03T14:42:27.3293217Z System.TypeInitializationException: The type initializer for 'LibGit2Sharp.Core.NativeMethods' threw an exception. ---> System.DllNotFoundException: Unable to load shared library 'git2-572e4d8' or one of its dependencies. In order to help diagnose loading problems, consider setting the LD_DEBUG environment variable: libgit2-572e4d8: cannot open shared object file: No such file or directory
2021-03-03T14:42:27.3294576Z    at LibGit2Sharp.Core.NativeMethods.git_libgit2_init()
2021-03-03T14:42:27.3295127Z    at LibGit2Sharp.Core.NativeMethods.InitializeNativeLibrary()
2021-03-03T14:42:27.3295638Z    at LibGit2Sharp.Core.NativeMethods..cctor()
2021-03-03T14:42:27.3296343Z    --- End of inner exception stack trace ---
2021-03-03T14:42:27.3297253Z    at LibGit2Sharp.Core.NativeMethods.git_buf_dispose(GitBuf buf)
2021-03-03T14:42:27.3297767Z    at LibGit2Sharp.Core.Proxy.ConvertPath(Func`2 pathRetriever)
2021-03-03T14:42:27.3298268Z    at LibGit2Sharp.Repository.Discover(String startingPath)
2021-03-03T14:42:27.3298871Z    at GitVersion.GitPreparer.GetDotGitDirectory() in D:\a\1\s\src\GitVersionCore\GitPreparer.cs:line 148
2021-03-03T14:42:27.3299616Z    at GitVersion.GitPreparer.GetProjectRootDirectory() in D:\a\1\s\src\GitVersionCore\GitPreparer.cs:line 162
2021-03-03T14:42:27.3300622Z    at GitVersion.ConfigFileLocator.Verify(GitPreparer gitPreparer, IFileSystem fileSystem) in D:\a\1\s\src\GitVersionCore\Configuration\ConfigFileLocator.cs:line 57
2021-03-03T14:42:27.3301485Z    at GitVersion.Program.VerifyArgumentsAndRun() in D:\a\1\s\src\GitVersionExe\Program.cs:line 95
2021-03-03T14:42:27.3302064Z INFO [03/03/21 14:42:27:30] 
2021-03-03T14:42:27.3302631Z INFO [03/03/21 14:42:27:30] Attempting to show the current git graph (please include in issue): 
2021-03-03T14:42:27.3303249Z INFO [03/03/21 14:42:27:30] Showing max of 100 commits
2021-03-03T14:42:27.3339642Z ##[error]Error: The process '/usr/bin/dotnet' failed with exit code 1
2021-03-03T14:42:27.3371225Z ##[section]Finishing: GitVersion

Context

We temporarily changed our pipelines to use ubuntu 18.04 instead of 20.04 until this is fixed.

Steps to Reproduce

Run a GitVersion task in Azure DevOps pipeline with vmImage 20.04

  • Version Used: 5.0.1
  • Operating System and version (Windows 10, Ubuntu 18.04): Ubuntu 20.04

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:13 (8 by maintainers)

github_iconTop GitHub Comments

1reaction
arturciccommented, Mar 4, 2021

The latest version of GitVersion has started using LibGit2Sharp 0.27.0-preview-0096, right? You’ll have to be using that version if you want to run on Unbuntu 20.04.

@bording you are correct, we updated to 0.27.0-preview-0096 starting with v5.6.0

0reactions
arturciccommented, Mar 5, 2021

@annie-sumpter great it worked for you, closing this issue

Read more comments on GitHub >

github_iconTop Results From Across the Web

The type initializer for 'LibGit2Sharp.Core.NativeMethods' ...
Multiproject solution gives following error at runtime: “The type initializer for 'LibGit2Sharp.Core.NativeMethods' threw an exception” ...
Read more >
The type initializer for 'LibGit2Sharp.Core.NativeMethods ...
1) and when running its executable I get the following error: The type initializer for 'LibGit2Sharp.Core.NativeMethods' threw an exception.
Read more >
The type initializer for 'LibGit2Sharp.Core.NativeMethods' ...
Core.NativeMethods' threw an exception. —> System.DllNotFoundException: Unable to load DLL 'C:\Users\admin\AppData\Local\Programs\ ...
Read more >
Struggling with LibGit2Sharp - "DllNotFoundException: git2 ...
Rethrow as TypeInitializationException: The type initializer for 'LibGit2Sharp.Core.NativeMethods' threw an exception. LibGit2Sharp.Core.
Read more >
XAML build service fails with: “The type initializer for ...
The type initializer for 'LibGit2Sharp.Core.NativeMethods' threw an exception. The setup included a TFS 2015 server and a separate machine ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found