This project is read-only.

zip.Save(new MemoryStream()) throws ObjectDisposedException

Aug 29, 2011 at 1:21 PM
Edited Aug 29, 2011 at 1:56 PM

Hi everyone :)

Here's my snippet :


public void WriteMyZip(Stream outputStream)
   using (var zip = new ZipFile())
      zip.AddEntry(fileName, otherStream);


When i call it with a memorystream :


_service.WriteMyZip(new MemoryStream());


I get the exception.

What did i miss ? Are there options needed ?

Thanks :)


edit : my stacktrace

   at System.IO.__Error.StreamIsClosed()
   at System.IO.MemoryStream.get_Length()
   at Ionic.Zip.ZipEntry.SetInputAndFigureFileLength(Stream& input) in c:\DotNetZip\Zip\ZipEntry.Write.cs:line 1456
   at Ionic.Zip.ZipEntry._WriteEntryData(Stream s) in c:\DotNetZip\Zip\ZipEntry.Write.cs:line 1355
   at Ionic.Zip.ZipEntry.Write(Stream s) in c:\DotNetZip\Zip\ZipEntry.Write.cs:line 2182
   at Ionic.Zip.ZipFile.Save() in c:\DotNetZip\Zip\ZipFile.Save.cs:line 168
   at Ionic.Zip.ZipFile.Save(Stream outputStream) in c:\DotNetZip\Zip\ZipFile.Save.cs:line 584

I can't figure out where the stream is closed :/

Aug 29, 2011 at 2:28 PM

Allright, i figured it out : visual studio showed to me that the exception occured in the save() method. It mislead me to believe that the closed stream was the outputstream.

In fact, it was the "otherstream" that was closed, it makes more sense.

My code was crappy, that's my bad. But if you should test against this case (with an appropriate error message) that would be helpful for the other code-crapper like me ;p

Thanks :)