Can't find System.IO.Compression assembly

Viewed 5683

When calling the System.IO.Compression.Zipfile.CreateFromDirectory, I am met with the following error :

Exception on System.IO.Compression

However, my project does contain the first version of the assembly mentioned in the error (seen in the screenshot below).

After searching around, I saw that this error could arise from not having the System.IO.Compression.FileSystem assembly, which this project has : enter image description here

I tried using / removing the System.IO.Compression.Zipfile assembly (which I found out is just a "link" to System.IO.Compression.FileSystem), changing System.IO.Compression versions, but nothing worked.

This project runs under the .NET Framework 4.6.1.
Does anyone have an idea of how to troubleshoot this one ? Thanks !

2 Answers

In my case I added the following to web.config runtime/assemblyBinding node:

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

You can manually add the following binding redirect in your application's config file:

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

Change this

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

To

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