我正在开发一个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>
可能的原因是什么?
我知道提供的信息可能不多,但如果需要,我可以提供更多的细节。