代码之家  ›  专栏  ›  技术社区  ›  Rigerta

“libgit2shap.core.nativeMethods”的类型初始值设定项引发了异常

  •  1
  • Rigerta  · 技术社区  · 8 年前

    我正在开发一个C控制台应用程序 (.NET 4.6.1) 当运行它的可执行文件时,我得到以下错误:

    “libgit2sharp.core.nativeMethods”的类型初始值设定项引发了 例外。

    错误描述:

    在 libgit2shap.core.nativemethods.git_repository_open(git_repository*& 存储库,文件路径)
    在libgit2sharp.core.proxy.git_repository_open(字符串路径)
    在libgit2sharp.repository..ctor(字符串路径,repositoryOptions选项, RepositoryRequiredParameter RequiredParameter)
    在libgit2sharp.repository..ctor(字符串路径)
    在myproj.myclass.getMaxBranchVersion(字符串 回购)

    内部异常:

    System.IO.FileNotFoundException:无法加载文件或程序集 'System.Runtime.InteropServices.RuntimeInformation,版本=0.0.0.0, Culture=Neutral,PublicKeyToken=b03f75f7f11d50a3a'或其一个 依赖关系。系统找不到指定的文件。文件名: 'System.Runtime.InteropServices.RuntimeInformation,版本=0.0.0.0, 文化=中性,publicKeyToken=b03f5f7f11d50a3a'at libgit2sharp.core.platform.get operatingSystem()位于 libgit2shap.core.nativeMethods..cctor()。

    现在,项目的代码在调试或使用Visual Studio运行时可以正常工作-当尝试将其作为可执行文件运行时,会出现错误。 问题不在于 获取MaxBranchVersion 方法本身,因为我尝试根本不调用它,而这只会导致在运行下一个方法时出现错误。

    我尝试根据将以下配置项添加到.csproj文件 this answer 但不幸的是,它没有解决我的问题:

    <PropertyGroup>
    ..
    <AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
    <GenerateBindingRedirectsOutputType>true</GenerateBindingRedirectsOutputType>
    ..
    </PropertyGroup>
    

    可能的原因是什么?

    我知道提供的信息可能不多,但如果需要,我可以提供更多的细节。

    1 回复  |  直到 8 年前
        1
  •  0
  •   Rigerta    8 年前

    我通过以下步骤解决了我的问题:

    1. 改变了 Target Framework 为了项目 .NET 4.7
    2. 复制了 System.Runtime.InteropServices.RuntimeInformation.dll 在我试图运行可执行文件的文件夹中

    此时,我得到了另一个错误:

    System.dllnotFoundException:无法加载dll“git2-6311e88”:该 找不到指定的模块。(来自hresult的异常: 0x8007007e)在libgit2sharp.core.nativeMethods.git_libgit2_init()处
    在libgit2shap.core.nativeMethods.loadNativeLibrary()的 libgit2shap.core.nativeMethods..cctor()。

    多亏了 this answer 我能够克服这个问题 同时复制 git2-6311e88.dll (在我的案例中需要x86版本,通常位于 bin/debug 或 bin/release 文件夹,位于 lib/os-version ,在我的情况下 lib/win32 )

    嘿!它起作用了!祝所有在同一问题上挣扎的人好运。