【问题标题】:'Could not load type 'System.IO.Compression.ZipFile' from assembly 'Newtonsoft.Json''无法从程序集'Newtonsoft.Json'中加载类型'System.IO.Compression.ZipFile'
【发布时间】:2020-08-06 21:32:01
【问题描述】:

我正在使用 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.ZipFileNewtonsoft.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 的包引用:

<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>

【问题讨论】:

    标签: wpf .net-core nuget publish .net-core-3.1


    【解决方案1】:

    即使我多次尝试在未选中“修剪未使用的程序集(预览版)”复选框的情况下发布应用程序,但事实证明它还没有被处理。从 .csproj 中删除冗余标签后,问题已得到解决。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-04-08
      • 1970-01-01
      • 2012-05-05
      • 1970-01-01
      • 2011-09-07
      • 2016-09-27
      • 2010-11-30
      • 1970-01-01
      相关资源
      最近更新 更多