3

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 !

Hurlu'
  • 330
  • 4
  • 13
  • 2
    Did it work before? Do you have any binding redirection in `app.config`? Did you check the Fusion log? – dymanoid Jan 11 '19 at 11:24
  • It did work before, but I have not been able to pin-point the problematic commit. I have not made anything manually in app.config nor do I know what Fusion is : i'll search for this log right now ! – Hurlu' Jan 11 '19 at 11:26
  • 1
    If you use git, use git-bisect to quickly find the commit that caused the issue. – dymanoid Jan 11 '19 at 11:27
  • Are you sure the directory exists? – preciousbetine Jan 11 '19 at 11:32
  • @dymanoid Using Fusion Log, I managed to find out that the assembly was being searched for in Project1, that has a dependency on Project2 which itself uses the Zipfile method and System.Compression.IO.Filesystem. One way (tested and working) of fixing it would be to add System.Compression.IO to Project1, but isn't it a bit of a backwards way of doing it ? Shouldn't it work with Project2's dependencies ? – Hurlu' Jan 11 '19 at 11:35
  • clean the solution and remove/restore the Nuget package does not help? – Falco Alexander Jan 11 '19 at 11:43
  • @FalcoAlexander I did try that unsucessfully before. After following other commenters advice, the problem shifted as the Assembly was searched in the wrong place : check out my comment above if you are interested, I might post this as a temporary fix – Hurlu' Jan 11 '19 at 11:49
  • 1
    Chek [This](https://stackoverflow.com/questions/47048438/missingmethodexception-when-referencing-microsoft-build-and-system-io-compressio) and [This](https://github.com/Microsoft/dotnet/blob/master/releases/net471/KnownIssues/623552-BCL%20Higher%20assembly%20versions%20that%204.0.0.0%20for%20System.IO.Compression.ZipFile%20cannot%20be%20loaded%20without%20a%20binding%20redirect.md) – NaDeR Star Jan 11 '19 at 12:01
  • Check last answer on [This](https://stackoverflow.com/questions/33802239/cannot-find-ziparchive-in-the-system-io-compression-namespace) link – NaDeR Star Jan 11 '19 at 12:19

2 Answers2

3

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>
Matstar
  • 402
  • 3
  • 6
1

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> 
NaDeR Star
  • 647
  • 1
  • 6
  • 13
  • Tried it, but no changes. Thanks though ! If you check out my previous comments, you'll see that currently, the assembly is searched for in the wrong project. Any ideas about that ? – Hurlu' Jan 11 '19 at 12:06