.Net Core 无法加载主机策略.dll (HRESULT: 0x800700C1)



我正在将我的项目从.Net Core 2.2升级到3.1,但我遇到了一些问题。起初,通过命令行启动,我收到一条错误消息,指出在输出文件夹中找不到 hostpolicy.dll。要解决此问题,我安装了Microsoft.NETCore.DotNetHostPolicy,但现在我收到此错误消息:

Failed to load the dll from [*path*win-x86hostpolicy.dll], HRESULT: 0x800700C1
An error occurred while loading required library hostpolicy.dll from [*path*win-x86]

我看过一些关于更改运行时标识符的帖子,所以我将我的设置为win7-x86;win10-x64,但这对我没有任何作用。win7-x86之所以存在,是因为输出为 32 位对我的项目至关重要,否则我正在使用的程序集之一根本无法工作。现在,我让项目编译为DLL,以便我可以通过CMD启动并获得一些更详细的错误消息。

以下是我的.csproj中的更多信息:

<PropertyGroup>
<TargetFramework>netcoreapp3.1</TargetFramework>
<RuntimeIdentifiers>win7-x86;win10-x64</RuntimeIdentifiers>
<Platforms>x86</Platforms>
<OutputType>library</OutputType>
<TargetLatestRuntimePatch>true</TargetLatestRuntimePatch>
</PropertyGroup>

从我的.pubxml:

<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<WebPublishMethod>FileSystem</WebPublishMethod>
<PublishProvider>FileSystem</PublishProvider>
<LastUsedBuildConfiguration>Release</LastUsedBuildConfiguration>
<LastUsedPlatform>x86</LastUsedPlatform>
<SiteUrlToLaunchAfterPublish />
<LaunchSiteAfterPublish>True</LaunchSiteAfterPublish>
<ExcludeApp_Data>False</ExcludeApp_Data>
<TargetFramework>netcoreapp3.1</TargetFramework>
<RuntimeIdentifier>win-x86</RuntimeIdentifier>
<publishUrl>binReleasenetcoreapp3.1x86publish</publishUrl>
<DeleteExistingFiles>True</DeleteExistingFiles>
<SelfContained>true</SelfContained>
<_IsPortable>false</_IsPortable>
<PublishSingleFile>False</PublishSingleFile>
<PublishTrimmed>False</PublishTrimmed>
<PublishReadyToRun>False</PublishReadyToRun>
</PropertyGroup>
</Project>

我的运行时配置看起来像这个 atm:

{
"runtimeOptions": {
"tfm": "netcoreapp3.1",
"includedFrameworks": [
{
"name": "Microsoft.NETCore.App",
"version": "3.1.0"
},
{
"name": "Microsoft.AspNetCore.App",
"version": "3.1.0"
}
],
"configProperties": {
"System.GC.Server": true
}
}
}

虽然它可能不是一个特别好的解决方案,但我通过使用 .Net Core 3.1 创建一个新项目并导入所有相同的文件来修复它。从模板中对启动.cs和程序.cs进行了一些细微的更改以满足我的需求,现在它又开始工作了。

最新更新