This project is read-only.

Garbage Collector Issue

Sep 6, 2009 at 10:50 PM

Hi,

I am getting an error when using CompressDirectory

I am running VS2008, .Net3.5sp1, Windows 7 RTM x86, 7-zip 907

SevenZipCompressor.SetLibraryPath(@"C:\Program Files\7-Zip\7z.dll");
var tmp = new SevenZipCompressor();
tmp.ArchiveFormat = OutArchiveFormat.SevenZip;
tmp.CompressionLevel = CompressionLevel.Ultra;
tmp.CompressionMethod = CompressionMethod.Ppmd;

tmp.CompressDirectory(@"C:\Users\Bob\Documents\TestDir", @"C:\Users\Bob\Documents\TestDoc.7z");

the code blows up in Callback.cs when _MemoryPressure is 0

GC.AddMemoryPressure(_MemoryPressure); in CommonInit

again the same problem occurs

GC.RemoveMemoryPressure(_MemoryPressure); in Dispose

see part of the call stack below....

as a temporary fix I have added the following line in both functions

if (_MemoryPressure > 0)

this allows the code to run to a succesfull completion, but I am not sure if this is really the correct solution

any thoughts would be greatly appreciated

cheers

Frazer

 

Positive number required.
Parameter name: bytesAllocated

at System.GC.AddMemoryPressure(Int64 bytesAllocated)
   at SevenZip.ArchiveUpdateCallback.CommonInit(SevenZipCompressor compressor, UpdateData updateData, Boolean directoryStructure)
   at SevenZip.ArchiveUpdateCallback.Init(FileInfo[] files, Int32 rootLength, SevenZipCompressor compressor, UpdateData updateData, Boolean directoryStructure)
   at SevenZip.ArchiveUpdateCallback..ctor(FileInfo[] files, Int32 rootLength, SevenZipCompressor compressor, UpdateData updateData, Boolean directoryStructure)
   at SevenZip.SevenZipCompressor.GetArchiveUpdateCallback(FileInfo[] files, Int32 rootLength, String password)
   at SevenZip.SevenZipCompressor.CompressFilesEncrypted(Stream archiveStream, Int32 commonRootLength, String password, String[] fileFullNames)
   at SevenZip.SevenZipCompressor.CompressDirectory(String directory, Stream archiveStream, String password, String searchPattern, Boolean recursion)
   at SevenZip.SevenZipCompressor.CompressDirectory(String directory, String archiveName, String password, String searchPattern, Boolean recursion)
   at SevenZip.SevenZipCompressor.CompressDirectory(String directory, String archiveName)
  

Sep 7, 2009 at 2:04 PM
Edited Sep 7, 2009 at 2:08 PM

Got the same error with the latest build. I use your library to compress viewstate in aspx pages.

 

public static byte[] Compress(byte[] data)
        {
 
            SevenZipCompressor c = new SevenZipCompressor(); 
c.CompressionLevel = CompressionLevel.Ultra; MemoryStream input = new MemoryStream(data); MemoryStream output = new MemoryStream(); c.CompressStream(input, output); output.Position = 0; byte[] result = new byte[output.Length]; output.Read(result, 0, (int)output.Length); return result; }
Positive number required.
Parameter name: bytesAllocated 
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. 

Exception Details: System.ArgumentOutOfRangeException: Positive number required.
Parameter name: bytesAllocated

Source Error: 


Line 110:            MemoryStream input = new MemoryStream(data);
Line 111:            MemoryStream output = new MemoryStream();
Line 112:            c.CompressStream(input, output);
Line 113:            output.Position = 0;
Line 114:            byte[] result = new byte[output.Length];
 

Source File: ...    Line: 112 

Stack Trace: 


[ArgumentOutOfRangeException: Positive number required.
Parameter name: bytesAllocated]
   System.GC.AddMemoryPressure(Int64 bytesAllocated) +7546413
   SevenZip.ArchiveUpdateCallback.CommonInit(SevenZipCompressor compressor, UpdateData updateData, Boolean directoryStructure) +188
   SevenZip.ArchiveUpdateCallback.Init(Stream stream, SevenZipCompressor compressor, UpdateData updateData, Boolean directoryStructure) +215
   SevenZip.ArchiveUpdateCallback..ctor(Stream stream, SevenZipCompressor compressor, UpdateData updateData, Boolean directoryStructure) +46
   SevenZip.SevenZipCompressor.GetArchiveUpdateCallback(Stream inStream, String password) +174
   SevenZip.SevenZipCompressor.CompressStream(Stream inStream, Stream outStream, String password) +237
   SevenZip.SevenZipCompressor.CompressStream(Stream inStream, Stream outStream) +14
   
   ...
   System.Web.UI.Page.SaveAllState() +236
   System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +1099

 

Sep 7, 2009 at 6:45 PM
This discussion has been copied to a work item. Click here to go to the work item and continue the discussion.