NullReferenceException During Compression

Apr 29, 2010 at 11:24 PM

Greetings,

I am trying to use SevenZipCompressor to compress a file to a 7z file.  Below is the code snippet that I am using and below that is the exception I get within the call to the CompressStream method.  If I am doing something wrong please let me know as this is the first time I have used the SevenZipSharp library.   It seems rather straightforward and simple but maybe I am missing something.

SevenZipCompressor compressor = new SevenZipCompressor();
compressor.CompressStream(File.OpenRead("MyFile.txt"), File.Create("MyFile.7z"));

 

System.was unhandled
  Message="Object reference not set to an instance of an object."
  Source="SevenZipSharp"
  StackTrace:
       at SevenZip.SevenZipBase.ThrowException(SevenZipBase handler, Exception[] e)
       at SevenZip.SevenZipBase.CheckedExecute(Int32 hresult, String message, SevenZipBase handler)
       at SevenZip.SevenZipCompressor.CompressStream(Stream inStream, Stream outStream, String password)
       at LZMA.Program.Main(String[] args) in C:\Users\Rodney.Foley\Documents\Visual Studio 2008\Projects\Playground\LZMA\Program.cs:line 57
       at System.AppDomain._nExecuteAssembly(Assembly assembly, String[] args)
       at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
       at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
       at System.Threading.ThreadHelper.ThreadStart()
  InnerException: 

Apr 29, 2010 at 11:39 PM

BTW, if I swap out the call to CompressStream to CompressFiles as shown below it works fine.  These should be equivalent but one works and the other doesn't.  I think I may be able to use the one that is working have to double check some things to see if I can do without the Streams where we plan to use this.  It would be nice to know how to do this with streams.

compressor.DirectoryStructure = false;
compressor.CompressFiles("MyFile.7z", "MyFile.txt");        

Coordinator
May 3, 2010 at 6:46 AM
This discussion has been copied to a work item. Click here to go to the work item and continue the discussion.