Object Reference Not Set

May 5, 2009 at 6:42 PM
I'm working on an application which utilizes the SevenZipSharp library (Thank you very much for this, by the way).

After I added a SevenZipExtractor object to my application, I started getting an "Object reference not set to an instance of an object." error when the application closes.  The extractor works perfectly fine while the application is running, and I've commented out code to isolate the problem.  The following line is what seems to be causing the problem, as if I comment it out (also commenting out all of the actual usage of the object, as well), the application closes just fine. 

SevenZipExtractor ArchiveExtractor = new SevenZipExtractor(archiveFile);

archiveFile is a string passed to a method which performs the actual extraction.  If I comment out all of the actual extraction code, and just leave this constructor assignment, the application displays the error when closing.  Any ideas or suggestions as to what I might be doing wrong?
May 5, 2009 at 6:50 PM
I changed my code to call the constructor with a FileStream, rather than the filename as a string, and this exception is no longer occurring.  Easy enough fix, but I'm thinking there might be some sort of bug with the string version of the constructor.
Coordinator
May 6, 2009 at 10:59 AM
Hi, CovertDad.

First, I recommend you to enclose SevenZipExtractor into the using structure:
using (SevenZipExtractor ArchiveExtractor = new SevenZipExtractor(archiveFile))
{
//code
}
It is guaranteed that you will not receive any exceptions.

The exception you get is definitely a bug. Please post the exception text (message, stack trace - everything from Exception.ToString()).

Thanks in advance.
May 6, 2009 at 1:42 PM
Edited May 6, 2009 at 1:44 PM
The information for the exception is as follows:

System.NullReferenceException was unhandled
  Message="Object reference not set to an instance of an object."
  Source="SevenZipSharp"
  StackTrace:
       at SevenZip.SevenZipLibraryManager.FreeLibrary(Object user, Enum format)
       at SevenZip.SevenZipExtractor.Dispose()
       at SevenZip.SevenZipExtractor.Finalize()
  InnerException:

Like I said before, everything works fine if I use the Stream constructor of the SevenZipExtractor.  Also, the string constructor works fine with the using statement.  Hope this helps!