libgit2sharp icon indicating copy to clipboard operation
libgit2sharp copied to clipboard

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

Open AndreZila01 opened this issue 2 years ago • 1 comments

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");
		}

AndreZila01 avatar Jan 08 '23 12:01 AndreZila01

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.

Flayms avatar Mar 28 '23 12:03 Flayms