dotdevelop/libgit2sharp

Debian: type initializer for 'LibGit2Sharp.Core.NativeMethods' threw an exception

lytico opened this issue · 8 comments

See
libgit2#1533 (comment)
and
dotdevelop/dotdevelop#52 (comment)

the branch to fix it is this: https://github.com/dotdevelop/libgit2sharp/tree/dd/issues/2

the git hash for libgit is 6777db8e8343014d57c41b335e0c60af44d4e9f2 ->

so, according to @Molytho , the problem is in the mismatch from

https://github.com/dotdevelop/libgit2/blob/6777db8e8343014d57c41b335e0c60af44d4e9f2/include/git2/status.h#L170-L197

to

[StructLayout(LayoutKind.Sequential)]
internal class GitStatusOptions : IDisposable
{
public uint Version = 1;
public GitStatusShow Show;
public GitStatusOptionFlags Flags;
public GitStrArrayManaged PathSpec;
public void Dispose()
{
PathSpec.Dispose();
}
}

calling

using (StatusListHandle list = Proxy.git_status_list_new(repo.Handle, coreOptions))

I started testing and I think I found a solution/workaround. I don't know how to set the project up properly to use a self build nuget for libgit2-sharp so I changed it to a project reference so this might not be 100% accurate.

First I compiled it with a clean clone of this repo. It didn't work.
Then I added the line
public unsafe void* Baseline = (void*)0;
to the end of the GitStatusOptions class. After that it worked fine.

It's surprising that this mis-match hasn't caused problems long before now! It seems to be in the current master and latest release (maint/v0.26) branches of github/libgit2/libgit2sharp, and not just the mono/dotdevelop forks.
Well tracked down @Molytho!

maybe it has to do with a more sever (and saver) memory access control in recent versions of mono?

and, yes, @Molytho did a great job, and he should upstream that error in the github/libgit2/libgit2sharp - repo.

Could the LibGit2Sharp.NativeBinaries be updated with this change, together with the dotdevelop build, please (even though the 'no TLS stream' issue is still outstanding)? Thanks.

Yes. Done..

The fix got merged to upstream:
libgit2@b78b290

That's great. It seems that this has now fixed a problem that upstream libgit2 were having with dotnet runtime 5.0.7, so many thanks all round @Molytho !