System.ExecutionEngineException

Mar 25, 2009 at 3:01 PM
I have built an application that accepts a root directory input from the user.  it then uses the DirectoryInfo object to gather all directory names in the root folder.  After the directory array is full, I step thru the array and process each directory element.  the loop looks like this:

 

For Each dri In diArr
    AddLog(
"Zipping directory \" & dri.Name)
    lblCommand.Text = strInput & dri.Name
    lblCommand.Refresh()
    strTargetZipDir = strInput & dri.Name
    strNewZipFileName = dri.Name &
".7z"
    
strNewZipFilePath = strInput & strNewZipFileName
    ' Compress directory
    Dim szc As New SevenZipCompressor()
    szc.CompressDirectory(strTargetZipDir, strNewZipFilePath, OutArchiveFormat.SevenZip)
    AddLog(
"Zip file created :: " & strNewZipFileName)
    iProcessed = iProcessed + 1
    DoEvents()
Next dri

this works as desired.  once completed, the user form is updated with results, counts, etc.  the form controls are re-enabled and the user can exit or enter a new directory and start again.

if the user chooses to start again, on the first pass thru for...next they are met with the error listed in the subject of this post.  it doesnt matter if they choose the same root as the first time thru or if they choose a new root.

if you need more information, please ask.  i am willing to do whatever it takes to solve this problem.

 

 

Coordinator
Mar 25, 2009 at 9:27 PM
Thanks for the details, I will check this issue tomorrow.
Coordinator
Mar 26, 2009 at 9:32 PM
Edited Mar 26, 2009 at 9:35 PM
Please note that CompressDirectory is fully recursive (enumerates all directories in the root directory like you do and compress them) and all you have to do is to call it with the root folder parameter. To display progress, set FileCompressionStarted or Compressing events.

If this note does not help you, try to uncomment lines in LibraryManager.cs #181 and #193.

Waiting for your response...
Mar 27, 2009 at 5:23 AM
the problem though is that it enumerates all directories and then compresses all directories into one zip.  i need to enumerate all directories and then compress each directory into a separate zip file.  one zip file per directory.  if there is a way to do it with the compressdirectory method and save me the extra steps i would love to do it.  i just didnt see how to do it.
 
when i uncommented the code i received a new error:
 
    "COM object that has been separated from its underlying RCW cannot be used."

error was thrown in same place as above but gave a different message.

place error is thrown is in sevenzipcompressor.cs line 379:

    CheckedExecute(

SevenZipLibraryManager.OutArchive(format).UpdateItems(ArchiveStream, (uint)files.Length, auc),SevenZipCompressionFailedException.DefaultMessage);

 

Mar 27, 2009 at 10:38 AM
Hi,

Could you provide more details about the exception, as the exception class is far from enough.

You should provide at least the exception message, and the stack trace. If you defined the actual line where the exception occured, it would be perfect!

Best regards,
GS
Mar 27, 2009 at 2:53 PM
ok.  exact details to the best of my ability are as follows.

I need an app to traverse a root directory, non-recursively, and make a unique zip file for each subdirectory within the root directory.  one zip file per sub.  if there are 9 subdirectories in the root directory, there will be 9 zip files.

here is a trimmed down version of the code in c#.  i am writing in vb.net but translated to c# as well just to see if that may be the problem.  as well, i thought it may be easier for you folks to help since this is written in c#.  if i am mistaken, accept my apologies.

static
void Main(string[] args)
{
    string sName;
    
    SevenZipCompressor
.SetLibraryPath(@"c:\Program Files\7-Zip\7z.dll"); 
    
    DirectoryInfo
mydi = new DirectoryInfo(@"c:\test");
    DirectoryInfo[] mydiArr = mydi.GetDirectories();
    
    foreach
(DirectoryInfo mydri in mydiArr)
    {
        sName = mydri.FullName +
".7z";
        SevenZipCompressor tmp = new SevenZipCompressor();
        tmp.CompressDirectory(mydri.FullName, sName,
OutArchiveFormat.SevenZip);
        Console.WriteLine(mydri.Name);
    }
    Console.ReadKey();
}

The error is consistent only in that it will always happen.  It is inconsistent in that it wont always happen at the same interation.  For instance, in this code snippet, the app makes it through the first pass of the for...next loop and then errors when trying to compress the second directory. 

The error comes in SevenZipCompressor.cs at Line 379 in the following chunk of code:

    CheckedExecute(SevenZipLibraryManager.OutArchive(format).UpdateItems(ArchiveStream, (uint)files.Length, auc),SevenZipCompressionFailedException.DefaultMessage);

below is the exception detail:

    System.AccessViolationException was unhandled
    Message="Attempted to read or write protected memory. This is often an indication that other memory is corrupt."
    Source="SevenZipSharp"
    StackTrace:
       at SevenZip.ComRoutines.IOutArchive.UpdateItems(ISequentialOutStream outStream, UInt32 numItems, IArchiveUpdateCallback updateCallback)
       at SevenZip.SevenZipCompressor.CompressFiles(String[] fileFullNames, String commonRoot, Stream archiveStream, OutArchiveFormat format, String password) in C:\Documents and Settings\mlehmann\desktop\SevenZipSharp\SevenZip\SevenZipCompressor.cs:line 379
       at SevenZip.SevenZipCompressor.CompressDirectory(String directory, Stream archiveStream, OutArchiveFormat format, String password, String searchPattern, Boolean recursion) in C:\Documents and Settings\mlehmann\desktop\SevenZipSharp\SevenZip\SevenZipCompressor.cs:line 597
       at SevenZip.SevenZipCompressor.CompressDirectory(String directory, String archiveName, OutArchiveFormat format, String password, String searchPattern, Boolean recursion) in C:\Documents and Settings\mlehmann\desktop\SevenZipSharp\SevenZip\SevenZipCompressor.cs:line 557
       at SevenZip.SevenZipCompressor.CompressDirectory(String directory, String archiveName, OutArchiveFormat format) in C:\Documents and Settings\mlehmann\desktop\SevenZipSharp\SevenZip\SevenZipCompressor.cs:line 405
       at SevenZipTest.Program.Main(String[] args) in C:\Documents and Settings\mlehmann\desktop\SevenZipSharp\SevenZipTest\Program.cs:line 44
       at System.AppDomain._nExecuteAssembly(Assembly assembly, String[] args)
       at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
       at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
       at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
       at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
       at System.Threading.ThreadHelper.ThreadStart()
  InnerException:

That is all I have for now.   if you need more info, please ask and I will be happy to give anything I can.  This is a great project and I hope to do my part in helping.

Thanx.
Mar 27, 2009 at 3:42 PM
Edited Mar 27, 2009 at 3:51 PM
Hi, thanks for these details,

Well, the second exception is different from the one that you had in the beginning, but for the record, I had the same exception offur for me the day before. I'm not really sure why it happened, I assumed it had to do something with multi-threading (I was decompressing something like 900 archives on 15 threads). Here's my exception info: 

Attempted to read or write protected memory. This is often an indication that other memory is corrupt.

Source: SevenZipSharp
Target: Int32 Open(SevenZip.ComRoutines.IInStream, UInt64 ByRef, SevenZip.ComRoutines.IArchiveOpenCallback)
Stack Trace:
[System.AccessViolationException: Attempted to read or write protected memory. This is often an indication that other memory is corrupt.]
at SevenZip.ComRoutines.IInArchive.Open(IInStream stream, UInt64& maxCheckStartPosition, IArchiveOpenCallback openArchiveCallback)
at SevenZip.SevenZipExtractor.GetArchiveInfo() in C:\inetpub\Sinch\External\SevenZipSharp\SevenZip\SevenZipExtractor.cs:line 421
at SevenZip.SevenZipExtractor.ExtractArchive(String directory, Boolean reportErrors) in C:\inetpub\Sinch\External\SevenZipSharp\SevenZip\SevenZipExtractor.cs:line 985
at SevenZip.SevenZipExtractor.ExtractArchive(String directory) in C:\inetpub\Sinch\External\SevenZipSharp\SevenZip\SevenZipExtractor.cs:line 1051

Mar 27, 2009 at 5:12 PM
the first message is what i received when i uncommented the lines that markov suggested in his post.  the latter exception message is the message that prompted this discussion thread.

interestingly, though, i do get different exceptions between C# and vb.net.  same place and same error just worded different and the stack trace in # is much more detailed.

for the record, i am not doing any mulit-threading.
Mar 27, 2009 at 7:08 PM
i would be happy to upload my code project and the test data folder i am working with if you give me a place to put it.

let me know.
Coordinator
Mar 27, 2009 at 10:19 PM
>i would be happy to upload my code project and the test data folder i am working with if you give me a place to put it.
please use Issue Tracker to upload the code and the test data folder.

Try debugging with the following modified code:

//Before the loop
Debug.Listeners.Add(new TextWriterTraceListener("debug.log"));

Callbacks.cs Line 551.
public int GetUpdateItemInfo(uint index, ref int newData, ref int newProperties, ref uint indexInArchive)
        {
            try
            {
                newData = 1;
                newProperties = 1;
                indexInArchive = UInt32.MaxValue;
            }
            catch (AccessViolationException)
            {
                Debug.Fail("GetUpdateItemInfo AccessViolationException");
            }
            return 0;
        }

This is all that I think right now, waiting for your issue files.
Coordinator
Mar 27, 2009 at 10:26 PM
gregshutdown: looks like incorrect pointers coming from 7zip dll (maybe, an internal 7zip bug?).
I will try to replace all "ref int" with IntPtr to see if I am right.
Mar 30, 2009 at 3:05 PM
I tried that and the code never actually made it to the point of debug.fail.

i am willing to send you the zipped project file if you can tell me where to send it.



Coordinator
Mar 31, 2009 at 8:16 PM
Feel free to send anything to gmarkhor@gmail.com
Coordinator
Apr 3, 2009 at 8:41 PM
This nasty issue prevents from changing the library status from beta to stable, i will try hard to fix it this weekend.
Coordinator
Apr 3, 2009 at 9:21 PM
Edited Apr 3, 2009 at 9:28 PM
It seems like I have fixed this error!

I did a ten year old boy mistake:

After Marshal.ReleaseComObject(_InArchives[(InArchiveFormat)format]); (line 180) I had to write
_InArchives[(InArchiveFormat)format] = null; (and so it is with line 193).

This explains everything. Multi-threading works fine. By the way, the article http://msdn.microsoft.com/en-us/library/aa159887(office.11).aspx helped me very much.

The fixed code was committed to SVN.
Apr 3, 2009 at 10:30 PM
Oh WOW!!!

I had a feeling that the line had to be in there, and after reading a couple of articles about COM in .NET the feeling just got stronger. But it just didn't work when the line was there =/
Congrats on the fix! That's a massive thing, and I'm really happy it's fixed now :)

*triple cheers*

Keep up the good work!

Best regards,
GC
Coordinator
Apr 3, 2009 at 11:04 PM
Thank you! ^_^
Coordinator
Apr 5, 2009 at 2:44 PM
This discussion has been copied to a work item. Click here to go to the work item and continue the discussion.