Click here to Skip to main content
Click here to Skip to main content

Bug when using the classes to write zip files

, 8 May 2004 CPOL
Rate this:
Please Sign up or sign in to vote.
Describes an issue when writing a binary file into a zip file using the classes


I was writing a little .NET app in C# and was looking for a small library that would let me read and write zip files. That's when my first Google search gave me a link to Using the Zip Classes in the J# Class Libraries to Compress Files and Data with C#. Great! - that was my first reaction, but it didn't last too long. You can read zip files alright, but when you write zip files, if you have binary files (as you most often will), the generated zip file will be corrupt and you can't read it back. Funnily, WinZip does open it (ignoring the header errors) and the suggested solution by a Microsoftie in the one of the MS NGs was to extract all files using WinZip and then to zip it back. LOL. Why'd anyone want to use the zipping libraries at all if they had the option of bringing WinZip into the picture?

There is not even a KB article on this bug - bad! I lost about half a day when I was using these classes because I initially thought it was something wrong in my code. Anyway, this is a warning to everyone. Do not use the J# class libraries for zipping/unzipping if you are using the BCL 1.1 version. Heath Stewart (C# MVP and CodeProject Editor) has informed me that the BCL 2.0 includes zipping functionality - so that's really good news. And until that comes out, a very good free alternative to the J# classes is SharpZipLib which I very strongly recommend.

Bug demo

  1. Create a new C# console app project
  2. Add a reference to vjslib (...Microsoft.NET\Framework\v1.1.4322\vjslib.dll)
  3. Copy/paste the following code into your main cs file :-
    using System;
    using System.IO;
    class MainClass
      static void Main(string[] args)
      static void BugDemo()
        //Write zip file
        ZipOutputStream os = new ZipOutputStream(
        ZipEntry ze = new ZipEntry("gluk.gif");
        os.putNextEntry(ze); fs = 
        sbyte[] buff = new sbyte[1024];
        int n = 0;
        while ((,0,buff.Length))>0)
        Console.WriteLine("Okay, the zip has been written.");
        //Read zip file
          //Bug will occur here
          ZipFile zf = new ZipFile("");  
          Console.WriteLine("Bug confirmed!");
  4. Now make sure you have a gluk.gif in the same folder as the executable.

  5. Compile and run.


There is no real workaround to the problem. You can use the alternative library I mentioned above or wait for Whidbey.


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

Nish Nishant

United States United States
Nish is a real nice guy who has been writing code since 1990 when he first got his hands on an 8088 with 640 KB RAM. Originally from sunny Trivandrum in India, he has been living in various places over the past few years and often thinks it’s time he settled down somewhere.
Nish has been a Microsoft Visual C++ MVP since October, 2002 - awfully nice of Microsoft, he thinks. He maintains an MVP tips and tricks web site - where you can find a consolidated list of his articles, writings and ideas on VC++, MFC, .NET and C++/CLI. Oh, and you might want to check out his blog on C++/CLI, MFC, .NET and a lot of other stuff -
Nish loves reading Science Fiction, P G Wodehouse and Agatha Christie, and also fancies himself to be a decent writer of sorts. He has authored a romantic comedy Summer Love and Some more Cricket as well as a programming book – Extending MFC applications with the .NET Framework.
Nish's latest book C++/CLI in Action published by Manning Publications is now available for purchase. You can read more about the book on his blog.
Despite his wife's attempts to get him into cooking, his best effort so far has been a badly done omelette. Some day, he hopes to be a good cook, and to cook a tasty dinner for his wife.

Comments and Discussions

Questionhow to open and read files from a zip file using jsp or java Pinmembersandhyamn8-Jun-07 20:56 
GeneralJava Zip PinmemberSanjitP11-Apr-07 23:28 
GeneralRe: Java Zip PinmemberWajeehAhmed16-Apr-07 2:30 
QuestionAlternative? Pinmemberevoluzion22-Dec-06 12:02 
AnswerRe: Alternative? PinmemberBrad Bruce22-Dec-06 12:19 
GeneralVB convert procedure PinmemberAlessandro Betti17-May-06 7:56 
Generalon text files Pinmemberdvsr27-Dec-05 14:33 
GeneralAlternative (with code) PinmemberElmue17-Nov-05 3:30 
GeneralA fix available from M$ Pinmemberrshearer31-Aug-05 11:43 
GeneralAnother big problem Pinmembernahumtakum15-May-04 1:31 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Terms of Use | Mobile
Web01 | 2.8.150326.1 | Last Updated 9 May 2004
Article Copyright 2004 by Nish Nishant
Everything else Copyright © CodeProject, 1999-2015
Layout: fixed | fluid