1

Closed

ZipOutputStream comment NullReferenceException

description

When using ZipOutputStream and including a comment, ZipOutputStream will throw a NullReferenceException on disposal.
 
Stack Trace:
at Ionic.Zip.ZipOutput.GenCentralDirectoryFooter(Int64 StartOfCentralDirectory, Int64 EndOfCentralDirectory, Zip64Option zip64, Int32 entryCount, String comment, Encoding encoding)
at Ionic.Zip.ZipOutput.WriteCentralDirectoryStructure(Stream s, ICollection`1 entries, UInt32 numSegments, Zip64Option zip64, String comment, Encoding encoding)
at Ionic.Zip.ZipOutputStream.Dispose(Boolean notCalledFromFinalizer)
 
Code example:
using (ZipOutputStream zipStream = new ZipOutputStream(OutputStream))
{
zipStream.CompressionLevel = Ionic.Zlib.CompressionLevel.None;
zipStream.Comment = "Cheeso is the man!";
//If you explicitly set UseUnicodeAsNecessary to false, the error no longer occurs. 
//zipStream.UseUnicodeAsNecessary = false;
// .... Write to stream
} //ex is thrown here
 
The environment is a Windows XP Professional x86 installation.
I noticed ProvisionalAlternateEncoding is null, and am wondering if that's what's is causing the exception.
 
Thanks for all your work on this library.
Closed Jun 15, 2011 at 12:54 PM by Cheeso
This is a duplicate of workitem 12634.It was fixed in changeset 79077. First binary with this fix: v1.9.1.6

comments

comius wrote Sep 28, 2010 at 7:05 PM

Workaround:
zout.UseUnicodeAsNecessary = true;

The problem is, that otherwise encoder isn't set (therefore NullReferenceException). The code could be fixed in 5 minutes.