Click here to Skip to main content
15,306,676 members
Articles / .NET
Posted 8 May 2004

Tagged as


23 bookmarked

Bug when using the classes to write zip files

Rate me:
Please Sign up or sign in to vote.
4.58/5 (16 votes)
8 May 2004CPOL2 min read
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 Nishant is a Principal Software Architect based out of Columbus, Ohio. He has over 17 years of software industry experience in various roles including Lead Software Architect, Principal Software Engineer, and Product Manager. Nish was a Microsoft Visual C++ MVP between 2002 and 2015.

Nish is an industry acknowledged expert in the Microsoft technology stack. He authored C++/CLI in Action for Manning Publications in 2005, and had previously co-authored Extending MFC Applications with the .NET Framework for Addison Wesley in 2003. In addition, he has over 140 published technology articles on and another 250+ blog articles on his WordPress blog. Nish is vastly experienced in team management, mentoring teams, and directing all stages of software development.

Contact Nish : If you are interested in hiring Nish as a consultant, you can reach him via his google email id voidnish.

Company Website :

Comments and Discussions

Questionhow to open and read files from a zip file using jsp or java Pin
sandhyamn8-Jun-07 19:56
Membersandhyamn8-Jun-07 19:56 
GeneralJava Zip Pin
SanjitP11-Apr-07 22:28
MemberSanjitP11-Apr-07 22:28 
GeneralRe: Java Zip Pin
WajeehAhmed16-Apr-07 1:30
MemberWajeehAhmed16-Apr-07 1:30 
QuestionAlternative? Pin
evoluzion22-Dec-06 11:02
Memberevoluzion22-Dec-06 11:02 
AnswerRe: Alternative? Pin
Brad Bruce22-Dec-06 11:19
MemberBrad Bruce22-Dec-06 11:19 
GeneralVB convert procedure Pin
Alessandro Betti17-May-06 6:56
MemberAlessandro Betti17-May-06 6:56 
Generalon text files Pin
dvsr27-Dec-05 13:33
Memberdvsr27-Dec-05 13:33 
GeneralAlternative (with code) Pin
Elmue17-Nov-05 2:30
MemberElmue17-Nov-05 2:30 
GeneralA fix available from M$ Pin
rshearer31-Aug-05 10:43
Memberrshearer31-Aug-05 10:43 
GeneralAnother big problem Pin
nahumtakum15-May-04 0:31
Membernahumtakum15-May-04 0:31 
Questionis it really corrupt? Pin
Radeldudel10-May-04 21:11
MemberRadeldudel10-May-04 21:11 
AnswerRe: is it really corrupt? Pin
Nish Nishant10-May-04 21:36
sitebuilderNish Nishant10-May-04 21:36 
GeneralRe: is it really corrupt? Pin
Radeldudel10-May-04 21:53
MemberRadeldudel10-May-04 21:53 
GeneralRe: is it really corrupt? Pin
Nish Nishant10-May-04 22:40
sitebuilderNish Nishant10-May-04 22:40 
GeneralRe: is it really corrupt? Pin
Radeldudel10-May-04 22:44
MemberRadeldudel10-May-04 22:44 
GeneralTry this code Pin
Valeri Makarov9-May-04 5:56
MemberValeri Makarov9-May-04 5:56 
GeneralRe: Try this code Pin
Nish Nishant9-May-04 6:18
sitebuilderNish Nishant9-May-04 6:18 
GeneralRe: Try this code Pin
foxrobert12-May-04 21:54
Memberfoxrobert12-May-04 21:54 
GeneralRe: Try this code Pin
Valeri Makarov12-May-04 22:49
MemberValeri Makarov12-May-04 22:49 
QuestionWorks fine for me ? Pin
Bee Master9-May-04 5:36
MemberBee Master9-May-04 5:36 
AnswerRe: Works fine for me ? Pin
Nish Nishant9-May-04 6:14
sitebuilderNish Nishant9-May-04 6:14 
GeneralRe: Works fine for me ? Pin
Bee Master11-May-04 5:58
MemberBee Master11-May-04 5:58 

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

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