我们正在使用 .net core 3.0 和 C# 构建一个更大的解决方案,其中一个项目是输出 exe 的控制台应用程序。我最近才开始研究它,但无法让它运行。当我在Visual Studio(2019,版本16.3.10,在Windows 10上运行(中以调试模式启动它时,我收到以下消息:
Invalid runtimeconfig.json [C:loong-pathprojectnamebinDebugnetcoreapp3.0projectname.runtimeconfig.json] [C:loong-pathprojectnamebinDebugnetcoreapp3.0projectname.runtimeconfig.dev.json]
C:loong-pathprojectnamebinDebugnetcoreapp3.0projectname.exe (process 3312) exited with code -2147450733.
To automatically close the console when debugging stops, enable Tools->Options->Debugging->Automatically close the console when debugging stops.
Press any key to close this window . . .
在查看runtimeconfig.json
时,它似乎非常简单且正确:
{
"runtimeOptions": {
"tfm": "netcoreapp3.0",
"framework": {
"name": "Microsoft.NETCore.App",
"version": "3.0.0"
}
}
}
runtimeconfig.dev.json
也是如此:
{
"runtimeOptions": {
"additionalProbingPaths": [
"C:\Users\myusername\.dotnet\store\|arch|\|tfm|",
"C:\Users\myusername\.nuget\packages",
"C:\Program Files\dotnet\sdk\NuGetFallbackFolder"
]
}
}
我尝试在构建之前进行清理,并在构建之前删除 bin 文件夹,但runtimeconfig.json
被重新生成并且看起来相同。
我尝试从控制台使用 dotnet 运行它,但获得的输出与 Visual Studio 基本相同。即使在将详细程度设置为诊断的情况下运行它也会产生相同的输出(dotnet run --no-build --verbosity diagnostic
(,这不是很有帮助。当我直接运行生成的projectname.exe
时,也会发生同样的情况。
我相当确定该程序应该可以工作,但存在其他一些潜在错误,因为相同的修订版适用于另外两个人的机器。但我真的在努力弄清楚问题到底是什么,因为它似乎真的不是自动生成的runtimeconfig.json
文件的问题。
像这样在 bin 文件夹中直接针对dll
运行dotnet
会产生实际的错误消息:C:loong-pathprojectnamebinDebugnetcoreapp3.0> dotnet projectname.dll
。
(潜在的错误原来是:
...
Unhandled exception. System.Exception: Failed to find or load OtherProjectName X509 certificate from local computer/personal certificate store.
---> System.ArgumentOutOfRangeException: Index was out of range. Must be non-negative and less than the size of the collection. (Parameter 'index')
at System.Collections.CollectionBase.System.Collections.IList.get_Item(Int32 index)
at System.Security.Cryptography.X509Certificates.X509CertificateCollection.get_Item(Int32 index)
at System.Security.Cryptography.X509Certificates.X509Certificate2Collection.get_Item(Int32 index)
...
这是由这个引起的:
var otherProjectNameClientCertificateColl = certificateStore
.Certificates
.Find(X509FindType.FindByThumbprint, _otherProjectNameCertificateStoreThumbprint, true);
var otherProjectNameClientCertificate = otherProjectNameClientCertificateColl[0];
(这是最后一行失败。
(