'无法从程序集 'Newtonsoft.Json' 加载类型 'System.IO.Compression.ZipFile'
'Could not load type 'System.IO.Compression.ZipFile' from assembly 'Newtonsoft.Json'
我正在使用 System.IO.Compression.ZipFile
NuGet 提取 .zip
存档。代码如下所示:
ZipFile.ExtractToDirectory(gameFolderAbsolutePath + api, gameFolderAbsolutePath, true);
使用在任何配置(调试/发布)中编译的应用程序时没有问题。当应用程序在发布后为 运行 时会出现问题,设置如下:
此已发布的应用程序 运行 后,它在上面显示的代码行崩溃并给出此异常消息:System.TypeLoadException: 'Could not load type 'System.IO.Compression.ZipFile' from assembly 'Newtonsoft.Json, Version=12.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed'.'
我不知道为什么要 System.IO.Compression.ZipFile
在 Newtonsoft.Json
中寻找一些东西。
Publish.pubx.xml:
<?xml version="1.0" encoding="utf-8"?>
<!--
https://go.microsoft.com/fwlink/?LinkID=208121.
-->
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<Configuration>Release</Configuration>
<Platform>Any CPU</Platform>
<PublishDir>P:\ReleaseCandidate\installer-binaries\data</PublishDir>
<PublishProtocol>FileSystem</PublishProtocol>
<TargetFramework>netcoreapp3.1</TargetFramework>
<RuntimeIdentifier>win-x86</RuntimeIdentifier>
<SelfContained>true</SelfContained>
<PublishSingleFile>True</PublishSingleFile>
<PublishReadyToRun>True</PublishReadyToRun>
<PublishTrimmed>True</PublishTrimmed>
</PropertyGroup>
</Project>
来自 .csproj 的 PackageReferences:
<ItemGroup>
<PackageReference Include="Microsoft.Extensions.Hosting" Version="3.1.6" />
<PackageReference Include="Microsoft.Extensions.PlatformAbstractions" Version="1.1.0" />
<PackageReference Include="NLog" Version="4.7.3" />
<PackageReference Include="RestSharp" Version="106.11.4" />
<PackageReference Include="RestSharp.Serializers.NewtonsoftJson" Version="106.11.4" />
<PackageReference Include="System.IO.Compression.ZipFile" Version="4.3.0" />
<PackageReference Include="System.Net.NameResolution" Version="4.3.0" />
<PackageReference Include="System.Runtime.InteropServices" Version="4.3.0" />
</ItemGroup>
尽管我已经多次尝试在未选中 'Trim unused assemblies (in preview)' 复选框的情况下发布应用程序,但结果是它还没有被处理。从 .csproj.
中删除冗余标签后问题已解决
我正在使用 System.IO.Compression.ZipFile
NuGet 提取 .zip
存档。代码如下所示:
ZipFile.ExtractToDirectory(gameFolderAbsolutePath + api, gameFolderAbsolutePath, true);
使用在任何配置(调试/发布)中编译的应用程序时没有问题。当应用程序在发布后为 运行 时会出现问题,设置如下:
此已发布的应用程序 运行 后,它在上面显示的代码行崩溃并给出此异常消息:System.TypeLoadException: 'Could not load type 'System.IO.Compression.ZipFile' from assembly 'Newtonsoft.Json, Version=12.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed'.'
我不知道为什么要 System.IO.Compression.ZipFile
在 Newtonsoft.Json
中寻找一些东西。
Publish.pubx.xml:
<?xml version="1.0" encoding="utf-8"?>
<!--
https://go.microsoft.com/fwlink/?LinkID=208121.
-->
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<Configuration>Release</Configuration>
<Platform>Any CPU</Platform>
<PublishDir>P:\ReleaseCandidate\installer-binaries\data</PublishDir>
<PublishProtocol>FileSystem</PublishProtocol>
<TargetFramework>netcoreapp3.1</TargetFramework>
<RuntimeIdentifier>win-x86</RuntimeIdentifier>
<SelfContained>true</SelfContained>
<PublishSingleFile>True</PublishSingleFile>
<PublishReadyToRun>True</PublishReadyToRun>
<PublishTrimmed>True</PublishTrimmed>
</PropertyGroup>
</Project>
来自 .csproj 的 PackageReferences:
<ItemGroup>
<PackageReference Include="Microsoft.Extensions.Hosting" Version="3.1.6" />
<PackageReference Include="Microsoft.Extensions.PlatformAbstractions" Version="1.1.0" />
<PackageReference Include="NLog" Version="4.7.3" />
<PackageReference Include="RestSharp" Version="106.11.4" />
<PackageReference Include="RestSharp.Serializers.NewtonsoftJson" Version="106.11.4" />
<PackageReference Include="System.IO.Compression.ZipFile" Version="4.3.0" />
<PackageReference Include="System.Net.NameResolution" Version="4.3.0" />
<PackageReference Include="System.Runtime.InteropServices" Version="4.3.0" />
</ItemGroup>
尽管我已经多次尝试在未选中 'Trim unused assemblies (in preview)' 复选框的情况下发布应用程序,但结果是它还没有被处理。从 .csproj.
中删除冗余标签后问题已解决