Problems with CrcCalculatorStream

Sep 28, 2010 at 4:09 PM

I found sample code in several places that is supposed to do a CRC check on a specific file within a Zip, but there are problems with the code.

I am hoping someone here will see what I am missing, the First thing was that the samples all referenced a class called Crc32 which doesn't exist but I was able to get around that by just using Crc with the 32.  I can't find any other samples of code that do this, so I am not sure what this "Object Reference" is.    It is on the "Using Ionic.Zlib.CrcCalculatorStream" line where I am getting the famous "Object Reference not set to an instance of Object"

         using (ZipFile zip = new ZipFile(ZipName))
              ZipEntry e1= zip[FileName];
              using (Ionic.Zlib.CrcCalculatorStream s = e1.OpenReader())               //--> *****  Blowing up on this line with "Object reference not set to an instance of object"
                  byte[] buffer = new byte[4096];
                  int n, totalBytesRead= 0;
                  do {
                       n = s.Read(buffer,0, buffer.Length);
                       totalBytesRead+= n;
                  while (n>0);
                  if (s.Crc != e1.Crc)  
                      Logger.Write(string.Format("The Zip Entry failed the CRC Check. (0x{0:X8}!=0x{1:X8})", s.Crc, e1.Crc));



Sep 29, 2010 at 4:31 AM
I'm guessing that e1 is null. That means that there is no entry in the zipfile with the filename you specified. You can confirm this quickly using a debugger. Good luck.