CloseDelegate can be called twice


I'm trying to port Fiddler to DotNetZip from the Xceed library. However, I'm having a problem with the AddEntry(string, OpenDelegate, CloseDelegate) method. Specifically, sometimes my close delegate is getting called twice (but Open is called only once), and that leads to an exception. Any idea why this might happen?
thanks for any tips!
Cannot access a closed Stream.;
at System.IO.MemoryStream.set_Position(Int64 value)
at Ionic.Zip.ZipEntry.PrepSourceStream()
at Ionic.Zip.ZipEntry.SetInputAndFigureFileLength(Stream& input)
at Ionic.Zip.ZipEntry._WriteEntryData(Stream s)
at Ionic.Zip.ZipEntry._EmitOne(Stream outstream)
at Ionic.Zip.ZipEntry.Write(Stream s)...

file attachments

Closed Jun 22, 2011 at 1:37 AM by Cheeso
This is fixed in a changeset prior to 79578. The fix will be in v1.9.1.6


Cheeso wrote Mar 23, 2010 at 6:51 PM

Eric, pls try this version of the DLL. SHA1: FE6F317A6CB59C2E81A5AF78C97963140FEE7FC8

wrote Mar 23, 2010 at 6:51 PM

jpoehls wrote May 27, 2010 at 2:25 PM

I'm also having this same problem using the Ionic.Zip.Reduced.dll (version

I tried using the Ionic.Zip.dll you attached and it fixed the problem. Is this fix part of a new official release yet?

wrote May 27, 2010 at 2:25 PM

Cheeso wrote Jun 2, 2010 at 10:30 PM

No - this fix is not yet part of any official release.
I never received confirmation on this.

wrote Jun 2, 2010 at 11:49 PM

wrote Jun 20, 2010 at 12:32 PM

rini wrote Nov 10, 2010 at 11:17 AM

I have the same problem using the AddEntry(string, OpenDelegate, CloseDelegate) method.
when the zipFile.CompressionLevel is left to Default value the close delegate is getting called twice leading to exception but when I set the zipFile.CompressionLevel to None the method runs with no exceptions.(actually all levels from level1 and up throw the same exception (Cannot access a closed file).
Any Ideas?

wrote Mar 16, 2011 at 12:57 AM

wrote Jun 13, 2011 at 7:57 PM

wrote Jun 22, 2011 at 1:37 AM

nicolasmasse wrote Oct 18, 2011 at 10:43 AM

Same problem here with version It seems that it happen when the readAgain variable in the ZipEntry.Write method is set to true after the first pass.
I fix this locally by adding this on line 1418 in ZipEntry.Write.cs :
  if (this._CloseDelegate != null)
  • {
      this._CloseDelegate(this.FileName, input);
  • this._sourceStream = null;
  • }
This makes the stream being reopened, avoiding crash

mika91 wrote Dec 12, 2011 at 4:26 PM


same problem on with very small files.

MarcosMeli wrote Jan 17, 2012 at 8:09 PM


Confirmed in Reduced

It throws: (Cannot access a closed file)

@Cheeso can you reopen it ?

wrote Feb 22, 2013 at 2:43 AM

wrote May 16, 2013 at 1:31 PM