1

I am writing a powershell script to run on a windows server 2008-r2 box running powershell v2, and it requires the ability to zip files. To do that, I need to have this line of code to import the assembly:

add-type -path "C:\Windows\Microsoft.NET\Framework64\v4.0.30319\System.IO.Compression.FileSystem.dll"

However, when I run the code, it errors with:

Add-Type : Could not load file or assembly 'file:///C:\Windows\Microsoft.NET\Framework64\v4.0.30319\System.IO.Compressi
on.FileSystem.dll' or one of its dependencies. This assembly is built by a runtime newer than the currently loaded runt
ime and cannot be loaded.

So I went to check what .NET version is installed using the registry method provided here: Microsoft: How to determine which .NET Framework versions are installed

And sure enough I am on

378758 == .NET Framework 4.5.1 installed on Windows 8, Windows 7 SP1, or Windows Vista SP2

And it even shows the install path as:

C:\Windows\Microsoft.NET\Framework64\v4.0.30319

Does anyone know what may be the issue here? Or what I can do as a workaround (Without software updates/installs).

  • Try Add-Type -Assembly System.IO.Compression.FileSystem – mzhaase May 2 '17 at 12:08
  • I received this error: "Cannot add type. The assembly 'System.IO.Compression.FileSystem' could not be found." – Christopher May 2 '17 at 12:13
  • Ok, try this path instead: Add-Type -Path "C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.5\System.IO.Compression.FileSystem.dll" – mzhaase May 2 '17 at 12:25
  • That path does not exist on my server.. I don't have a 'Reference Assemblies' folder in program files (x86) – Christopher May 2 '17 at 12:27
  • Possible duplicate of What does the ".NET Framework Version" setting in IIS actually do? – kenorb Oct 20 '17 at 13:08

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.