Unable to find `ZipArchive` in the System.IO.Compression namespace

My question is that I did not find the “ZipFile” class in the “System.IO.Compression” namespace

The type or namespace name 'ZipArchive' does not exist in the namespace 'System.IO.Compression'

But I referenced the DLL for my web forms project 4.5.1:

Screenshot of 'References' tab

The properties of my project give me: Target framework: .Net Framework 4.5.1. and web.config:

 <compilation debug="true" targetFramework="4.5" /> 

What am I missing?

The solution was to manually reference the assemblies in web.config. But why? Why was the check box in the add link dialog box insufficient?

 <assemblies> <add assembly="System.IO.Compression, Version=4.0.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089" /> <add assembly="System.IO.Compression.FileSystem, Version=4.0.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089" /> </assemblies> 

Taken from this answer to "Installed .Net 4.5, but cannot use the ZipFile class in Visual C #"

+17
reference c # webforms assemblies
source share
3 answers

I encountered the same problem because the namespace is missing from the links, follow these steps.

In my case, no links

When links are not set

After setting links

enter image description here Decision

1) Install system.Io.compression from nuget here

System.IO.Compression

2) Install system.Install-Package 40-System.IO.Compression.FileSystem from nuget here.

System.IO.Compression.FileSystem

+15
source share

you can directly update the links in the project file (upload the project and edit it or open the .csproj file with notepad and edit)

Before editing, it must match:

 <Reference Include="System.IO.Compression" /> <Reference Include="System.IO.Compression.FileSystem" /> 

After your editing:

 <Reference Include="System.IO.Compression, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089, processorArchitecture=MSIL" /> <Reference Include="System.IO.Compression.FileSystem, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089, processorArchitecture=MSIL" /> 

reload your project in Visual Studio and rebuild it. Hope this helps you.

+11
source share
 using (var zip = new ZipArchive(System.IO.File.OpenRead(zipFileName))) { ... } 
0
source share

All Articles