libgit2 / libgit2sharp

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

The type initializer for 'LibGit2Sharp.Core.NativeMethods' threw an exception #2005

Open AndreZila01 opened 1 year ago

AndreZila01 commented 1 year ago

I'm trying create a project to cloned my repository on start. But when i try do this in setup project i receive this message:
image

The code is simple, but in setup project dont work.

private void Form1_Load(object sender, EventArgs e)
        {
            LibGit2Sharp.Repository.Clone(@"https://github.com/libgit2/libgit2sharp.git", @"C:\Users\andre\Downloads\test");
        }
Flayms commented 1 year ago

I had the same Exception when using LibGit2Sharp (v0.26.2) in a .NET Framework 4.8 Project running the following code:

var directoryName = Directory.GetCurrentDirectory();
var isValid = Repository.IsValid(directoryName);

It's less a problem with the specific code you're calling and more with the initialization of LibGit2Sharp itself. Changing the platform target from Any CPU to either x64 or x86 is a way to resolve the problem. I didn't test this for other .NET or LibGit2Sharp Versions.