Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
lytico opened this issue Jan 24, 2021 · 8 comments · Fixed by #4
Closed

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

lytico opened this issue Jan 24, 2021 · 8 comments · Fixed by #4
Labels
bug Something isn't working

Comments

@lytico
Copy link
Member

lytico commented Jan 24, 2021

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 ->

@lytico
Copy link
Member Author

lytico commented Feb 2, 2021

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))

@Molytho
Copy link

Molytho commented Feb 16, 2021

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.

@hwthomas
Copy link

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!

@lytico
Copy link
Member Author

lytico commented Feb 26, 2021

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.

@hwthomas
Copy link

hwthomas commented Mar 4, 2021

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.

@lytico
Copy link
Member Author

lytico commented Mar 10, 2021

Yes. Done..

@Molytho
Copy link

Molytho commented Jun 18, 2021

The fix got merged to upstream:
libgit2@b78b290

@hwthomas
Copy link

hwthomas commented Jun 18, 2021

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 !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants