24

My question is related to I didn't find "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 have referenced the DLL's for my 4.5.1 webforms project:

Screenshot of 'References' tab

Properties of my project give me: Target framework: .Net Framework 4.5.1. and the web.config:

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

What am I missing?

The solution was to manually reference the assemblies in the web.config But why? Why wasn't the checkbox in the add reference dialog 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 can't use ZipFile class in Visual C#"

3
  • Are you getting any other message during compiling (such as assembly missing)? Output window might be useful.
    – Caramiriel
    Nov 19, 2015 at 12:04
  • 1
    You also need a reference to the System.IO.Compression.FileSystem. Whether or you checked is not visible. Nov 19, 2015 at 12:05
  • I have added the reference and it still gave me the assembly missing message. Adding the two lines in the web.config fixed it. But why? Normally is the add reference dialog sufficient. Nov 19, 2015 at 15:24

3 Answers 3

23

I faced same problem because the namespace is not present in References,Please do the following steps.

In my case Without References

When References not installed

After Installing References

enter image description here Solution

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

22

you can update References in Project file directly (Unload Project and Edit this or open .csproj file with notepad and edit)

Before edit must same as:

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

After your edit:

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

load again your project in Visual Studio and rebuild it. I hope it can help you.

1
  • Thank you for your answer, but I fixed it 2 years ago. Can you explain why the edit in the csproj fixes it? Oct 10, 2017 at 9:21
-1
using (var zip = new ZipArchive(System.IO.File.OpenRead(zipFileName))) { ... }
1
  • 5
    Welcome to Stack Overflow! While this code may solve the question, including an explanation of how and why this solves the problem would really help to improve the quality of your post, and probably result in more up-votes. Remember that you are answering the question for readers in the future, not just the person asking now. Please edit your answer to add explanations and give an indication of what limitations and assumptions apply.
    – Suraj Rao
    Apr 11, 2019 at 11:30

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.