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

但是,我的项目确实包含错误中提到的程序集的第一版(见下面的屏幕快照)。
在搜索之后,我发现这个错误可能是由于没有拥有程序集而产生的,这个项目具有:

我尝试过使用/移除System.IO.Compression程序集(我发现这只是一个指向System.IO.Compression.FileSystem的“链接”),改变了版本,但是没有什么效果。
该项目在.NET框架4.6.1下运行。
有人知道如何解决这个问题吗?谢谢!
发布于 2020-09-22 05:01:53
在我的示例中,我向web.config运行时/组装绑定节点添加了以下内容:
<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>发布于 2019-01-11 11:55:47
您可以在应用程序的配置文件中手动添加以下绑定重定向:
<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> https://stackoverflow.com/questions/54145504
复制相似问题