Wpf ';无法加载类型';System.IO.Compression.ZipFile';来自组件';Newtonsoft.Json';
我正在使用Wpf ';无法加载类型';System.IO.Compression.ZipFile';来自组件';Newtonsoft.Json';,wpf,.net-core,nuget,publish,.net-core-3.1,Wpf,.net Core,Nuget,Publish,.net Core 3.1,我正在使用System.IO.Compression.ZipFileNuGet来提取.zip存档文件。代码如下所示: ZipFile.ExtractToDirectory(gameFolderAbsolutePath + api, gameFolderAbsolutePath, true); 在任何配置(调试/发布)中使用编译后的应用程序时都没有问题。在应用程序发布后运行时,如果使用以下设置,则会出现问题: 运行此发布的应用程序后,它会在上面显示的代码行崩溃,并显示以下异常消息:System
System.IO.Compression.ZipFile
NuGet来提取.zip
存档文件。代码如下所示:
ZipFile.ExtractToDirectory(gameFolderAbsolutePath + api, gameFolderAbsolutePath, true);
在任何配置(调试/发布)中使用编译后的应用程序时都没有问题。在应用程序发布后运行时,如果使用以下设置,则会出现问题:
运行此发布的应用程序后,它会在上面显示的代码行崩溃,并显示以下异常消息:System.TypeLoadException:“无法从程序集“Newtonsoft.Json,Version=12.0.0.0,Culture=neutral,PublicKeyToken=30ad4fe6b2a6eed”加载类型“System.IO.Compression.ZipFile”。
我不知道为什么应该让System.IO.Compression.ZipFile
在Newtonsoft.Json
tho中查找一些东西
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>
释放
任何CPU
P:\ReleaseCandidate\installer binaries\data
文件系统
netcoreapp3.1
win-x86
真的
真的
真的
真的
来自.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>
即使我多次尝试在未选中“修剪未使用的程序集(预览中)”复选框的情况下发布应用程序,结果还是没有将其纳入流程。在从.csproj中删除冗余标记后,问题已得到解决。即使我多次尝试在未选中“修剪未使用的程序集(预览)”复选框的情况下发布应用程序,结果证明它尚未被纳入处理过程。从.csproj中删除冗余标记后,问题已得到解决