cake-contrib / Cake_Git

Cake AddIn that extends Cake with Git features using LibGit2 and LibGit2Sharp
https://cakebuild.net/extensions/cake-git
Other
39 stars 63 forks source link

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

Open vpaulino opened 5 years ago

vpaulino commented 5 years ago

Hi there

Im using package=Cake.Git on my cake script.... and it works on my machine :) but when I execute my build in my Jenkins CI it happens an error during script execution reporting an error with this log: "The type initializer for 'LibGit2Sharp.Core.NativeMethods' threw an exception". My Cake.Git package version is the lastest Cake.Git.0.19.0 and the agent OS is Microsoft Windows Server Version 1607 (OS Build 14393.2485).

Does anyone knows anything about this ?

devlead commented 5 years ago

Which version of .NET is installed?

Currently libgit2sharp requires .NET 4.7.2 / .NET Core 2, there's PR fir Libgit2Sharp to support 4.6.1 and once that's published I'll release a new version of Cake.Git.

RickRen7575 commented 4 years ago

@vpaulino do you know what resolved this issue? I am seeing the same issue.

GnktYnk commented 4 years ago

@vpaulino @RickRen7575 Did you resolve the issue or if it is resolved, possible to explain how it solved?

Cake.Git Version: 0.21.0 .NET Framework Version: 4.8

vpaulino commented 4 years ago

sorry for my disapearing on this. From what I recall on this the problem was the framework dotnet installed on the machine.. it was installed .Net 4.6, after upgrade it works. Sorry for the late answer... 2 years after.

CDTR-MattConroy commented 1 year ago

I am having this issue on MacOS. I'm using Cake 3.0.0, Cake.Git 3.0.0, and dotnet 7.0.102 It works fine on my Windows machine, but gets the same error message as above on MacOS: The type initializer for 'LibGit2Sharp.Core.NativeMethods' threw an exception

ehuna commented 1 year ago

Same here, on a Mac M1 now getting this error using Cake 2.0.0, Cake.Git 2.0.0, and tried with dotnet 7.0.203 and dotnet 6.0.408.

CDTR-MattConroy commented 1 year ago

@ehuna I managed to work around the issue by installing version 0.27.0-preview-0175. This is a preview version, but seems to not have the issue on Mac

ehuna commented 1 year ago

@CDTR-MattConroy thanks, we tried but that did not work for us. We ended up using git directly and no longer using Cake.Git.

For example instead of using GitLogTip(), we wrote our own like this -

private string GetGitHash()
{
    StartProcess(
        "git",
        new ProcessSettings()
            .WithArguments(x => x
                .Append("rev-parse")
                .Append("HEAD"))
            .SetRedirectStandardOutput(true),
            out var lines);

    var githash = string.Join(Environment.NewLine, lines);
    var result = githash.Trim();

    Information($"From GetGitHash(): {result}");

    return result;
}