【问题标题】:Can't find System.IO.Compression assembly找不到 System.IO.Compression 程序集
【发布时间】:2019-06-06 07:34:38
【问题描述】:

调用System.IO.Compression.Zipfile.CreateFromDirectory时,遇到以下错误:

但是,我的项目确实包含错误中提到的程序集的第一个版本(见下面的屏幕截图)。

四处搜索后,我发现这个错误可能是由于没有System.IO.Compression.FileSystem 程序集,这个项目有:

我尝试使用/删除System.IO.Compression.Zipfile 程序集(我发现它只是System.IO.Compression.FileSystem 的“链接”),更改System.IO.Compression 版本,但没有任何效果。

此项目在 .NET Framework 4.6.1 下运行。
有谁知道如何解决这个问题?谢谢!

【问题讨论】:

  • 以前有用吗? app.config 有绑定重定向吗?你检查过 Fusion 日志吗?
  • 它之前确实有效,但我无法确定有问题的提交。我没有在 app.config 中手动制作任何东西,也不知道 Fusion 是什么:我现在就搜索这个日志!
  • 如果你使用 git,使用 git-bisect 快速找到导致问题的提交。
  • 你确定目录存在吗?
  • 切克ThisThis

标签: c# nuget assemblies


【解决方案1】:

您可以在应用程序的配置文件中手动添加以下绑定重定向:

<runtime>
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
      <dependentAssembly>
        <assemblyIdentity name="System.IO.Compression.ZipFile" publicKeyToken="b77a5c561934e089" culture="neutral" />
        <bindingRedirect oldVersion="0.0.0.0-4.1.2.0" newVersion="4.1.2.0" />
      </dependentAssembly>
    </assemblyBinding>
  </runtime>

改变这个

 <runtime>
    <AppContextSwitchOverrides value="Switch.System.IO.Compression.ZipFile.UseBackslash=true" />
    </runtime>

 <runtime>
    <AppContextSwitchOverrides value="Switch.System.IO.Compression.ZipFile.UseBackslash=false" />
    </runtime> 

【讨论】:

  • 试过了,但没有任何变化。不过谢谢!如果您查看我以前的 cmets,您会发现当前在错误的项目中搜索了该程序集。有什么想法吗?
【解决方案2】:

在我的例子中,我将以下内容添加到 web.config runtime/assemblyBinding 节点:

<dependentAssembly>
  <assemblyIdentity name="System.IO.Compression" publicKeyToken="b77a5c561934e089" culture="neutral" />
  <bindingRedirect oldVersion="0.0.0.0-4.2.0.0" newVersion="4.0.0.0" />
</dependentAssembly>

【讨论】:

    猜你喜欢
    • 2018-02-27
    • 2010-10-19
    • 2011-09-23
    • 2011-03-20
    • 2011-03-02
    • 2017-06-28
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多