Error under macOS in PowerShell Core: The type initializer for 'LibGit2Sharp.Core.NativeMethods' threw an exception
See original GitHub issueReproduction steps
- Download LibGit2Sharp with the dotnet CLI
- Import it into PowerShell Core with
Import-Module
- Run
[LibGit2Sharp.Repository]::new($PWD)
in a git repository
Expected behavior
No error
Actual behavior
Error
Exception calling ".ctor" with "1" argument(s): "The type initializer for 'LibGit2Sharp.Core.NativeMethods' threw an exception."
At line:1 char:1
+ [LibGit2Sharp.Repository]::new($PWD)
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [], MethodInvocationException
+ FullyQualifiedErrorId : TypeInitializationException
Version of LibGit2Sharp (release number or SHA1)
v0.25.2
Operating system(s) tested; .NET runtime tested
> $PSVersionTable
Name Value
---- -----
PSVersion 6.0.2
PSEdition Core
GitCommitId v6.0.2
OS Darwin 17.6.0 Darwin Kernel Version 17.6.0: Tue May 8 15:22:16 PDT 2018; root:xnu-4570.61.1~1/RELEASE_X86_64
Platform Unix
PSCompatibleVersions {1.0, 2.0, 3.0, 4.0...}
PSRemotingProtocolVersion 2.3
SerializationVersion 1.1.0.1
WSManStackVersion 3.0
> dotnet --info
.NET Command Line Tools (2.1.4)
Product Information:
Version: 2.1.4
Commit SHA-1 hash: 5e8add2190
Runtime Environment:
OS Name: Mac OS X
OS Version: 10.13
OS Platform: Darwin
RID: osx.10.12-x64
Base Path: /usr/local/share/dotnet/sdk/2.1.4/
Microsoft .NET Core Shared Framework Host
Version : 2.0.5
Build : 17373eb129b3b05aa18ece963f8795d65ef8ea54
Issue Analytics
- State:
- Created 5 years ago
- Comments:30 (12 by maintainers)
Top Results From Across the Web
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' ...
Error: System.TypeInitializationException : The type initializer for 'LibGit2Sharp.Core.NativeMethods' threw an exception. —> System.
Read more >PowerShell connection from MacOS not working
Unfortunately logging in results in an error: Connect-SPOService: The type initializer for 'Microsoft.Win32.Registry' threw an exception ...
Read more >XAML build service fails with: “The type initializer for ...
The complete stack is given below: Exception Message: The type initializer for 'LibGit2Sharp.Core.NativeMethods' threw an exception.
Read more >The type initializer for 'LibGit2Sharp.Core.NativeMethods ...
Coding example for the question The type initializer for 'LibGit2Sharp.Core.NativeMethods' threw an exception-C#.
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
That code was an attempt to address some of the complexities involved in resolving the correct native libraries, but it turns out it only really works on Windows, so it’s not as helpful as it was thought it would be when the PR that added it was merged.
You might take a look at https://github.com/dotnet/sourcelink/tree/master/src/Microsoft.Build.Tasks.Git for ideas.
@felixfbecker
I was getting the same error: “The type initializer for ‘LibGit2Sharp.Core.NativeMethods’ threw an exception” under Windows. I saw a solution in the PSGit repository.