本机库 Repository Clone Libgit2sharp 没有提供任何错误消息

No error message has been provided by the native library Repository Clone Libgit2sharp

目前正在尝试克隆一个 gitlab 存储库(只能通过 VPN 访问)。通过 gitlab repo 的正常访问(没有 vpn)适用于 libgit2sharp。

var localFolder = "test";
var gitLabUrl = "some url";
var userNamePasswordCredentials = new UsernamePasswordCredentials()
{
    Username = gitConnection.UserName,
    Password = gitConnection.Password
};
Directory.CreateDirectory(localFolder);

var cloneOptions = new CloneOptions();
cloneOptions.CertificateCheck += (certificate, valid, host) => true;
try
{
     cloneOptions.CredentialsProvider = (_url, _user, _cred) => new DefaultCredentials();
     Repository.Clone(gitLabUrl, localFolder, cloneOptions);
}
catch (LibGit2SharpException ex)
{
    cloneOptions.CredentialsProvider = (_url, _user, _cred) => userNamePasswordCredentials;
    Repository.Clone(gitLabUrl, localFolder, cloneOptions);
}
 var repository = new Repository(localFolder);

我收到一个错误:

No error message has been provided by the native library

请推荐。

我能够使用以下命令克隆 git 存储库:

git -c http.sslVerify=false clone https://example.com/path/to/git

目前 LibGit2Sharp 没有通过将 sslVerify 设置为 false 来克隆 git 的工具。关闭此功能的一种方法是使用 link:

中的代码

https://github.com/libgit2/libgit2sharp/blob/master/LibGit2Sharp.Tests/desktop/SmartSubtransportFixture.cs

SmartSubtransportRegistration<MockSmartSubtransport> registration = null;
RemoteCertificateValidationCallback certificateValidationCallback = (sender,
                            certificate, chain, errors) => { return true; };

try
{
    ServicePointManager.ServerCertificateValidationCallback = certificateValidationCallback;
    registration = GlobalSettings.RegisterSmartSubtransport<MockSmartSubtransport>("https");

    var cloneOptions = new CloneOptions();
    cloneOptions.CertificateCheck += (certificate, valid, host) => true;

    cloneOptions.CredentialsProvider = (_url, _user, _cred) => new DefaultCredentials();
    Repository.Clone("https://url", "localFolder", cloneOptions);
  }
  finally
  {
      GlobalSettings.UnregisterSmartSubtransport(registration);
      ServicePointManager.ServerCertificateValidationCallback -= certificateValidationCallback;
  }

一些其他 links:

How can I make git accept a self signed certificate?