Exception that happens when your application is misconfigured in the web.config

Hi Folks! In this post I will show you how to fix the Could not load file or assembly 'System.IO.Compression' or one of its dependencies exception that happens when you update the package from Nuget or change the application's framework from 4.7 to 4.8 (for me the exception started to happen when I changed frameworks). The process is actually really simple, you just need to open the Powershell in your development/production machine:

  1. Open a Powershell Terminal Window;
  2. Type in ([system.reflection.assembly]::loadfile("{path to your faulty project}\bin\System.IO.Compression.dll")).FullName;
  3. Press enter (the following output will be displayed with the actual Version of the assembly along with the PublicKeyToken).

Take a look at the assembly version that is being shown. You should also confirm which PublicKeyToken is configured in your app/web.config file

Now go to your app/web.config (configuration > runtime element). Search for System.IO.Compression in the dependentAssembly and confirm which version is configured there. You should also confirm the PublicKeyToken. Modify your app/web.config file with the information from the Powershell Terminal Window (publicKeyToken and newVersion attributes).

Fixing the version in the Web.config

Voilà! Run your application and, if there're more Could not load file or assembly exceptions like that, repeat the 1-2-3 steps, replacing System.IO.Compression with the new assembly from the exception screen, until everything is good.