0

I am trying to create a zip folder and add a simple text file to it using my ASP.Net app running on .NET 4.6.1. I keep getting an error thrown and I have no idea how to correct it. The error is a result of trying to open the Readme.txt file. I have marked in the code where I am seeing the error. I notice that when trying to open the readmeEntry variable that it has Length and CompressedLength showing error 'System.InvalidOperationException'.

System.MissingMethodException: 'Method not found: 'Void System.IO.Compression.DeflateStream..ctor(System.IO.Stream, System.IO.Compression.CompressionLevel, Boolean)'.'

using (FileStream zipToOpen = new FileStream(path + "\\" + reportFileNameZip, FileMode.OpenOrCreate, System.IO.FileAccess.ReadWrite))
{
    using (ZipArchive archive = new ZipArchive(zipToOpen, ZipArchiveMode.Update, true))
    {
        ZipArchiveEntry readmeEntry = archive.CreateEntry("Readme." + "txt");
        using (StreamWriter writer = new StreamWriter(readmeEntry.Open()))
        {
           writer.WriteLine("Information about this package.");
        }
    }  //ERROR MESSAGE //
}
Camilo Terevinto
  • 31,141
  • 6
  • 88
  • 120
John Doe
  • 1,950
  • 9
  • 32
  • 53
  • 2
    I just ran your code from a console app. It works fine. How did you add a reference to System.IO.Compression? It somehow looks like the version of the reference added and the one being used do not match – Praveen Paulose Feb 23 '19 at 18:20
  • @PraveenPaulose ya I think it is an issue because I'm using ASP.net. I downloaded it from Nuget Manager. – John Doe Feb 23 '19 at 18:23
  • 1
    From NuGet? That package isn't officially in Nuget. Use the add reference dialog – Camilo Terevinto Feb 23 '19 at 18:25
  • I downloaded System.IO.Compression.ZipFile – John Doe Feb 23 '19 at 18:27
  • 1
    @JohnDoe I checked this in ASP.NET MVC too. Works fine. Can you check the version of your assembly in References and bin > Debug folder – Praveen Paulose Feb 23 '19 at 18:31
  • 1
    Tried to regenerate on 4.6.1 using nuget package, it is working fine. My System.IO.Compression version is 4.3.0. Btw, why do you need System.IO.Compression.ZipFile? – Nowshad Rahaman Feb 23 '19 at 18:32
  • Boom! Ya I just needed to add the Compression reference. Thanks everyone i was pulling my hair out on this one. – John Doe Feb 23 '19 at 18:34

0 Answers0