Home Forums .NET libraries Xceed Zip & Real-Time Zip for .NET Various Errors when trying to zip files in memory

Viewing 7 posts - 1 through 7 (of 7 total)
  • Author
    Posts
  • User (Old forums)
    Member
    Post count: 23064
    #20255 |

    Good Morning,

     

    I have a license copy of XCeed Zip for .NET (version 4.1.9373.11490).  I’m trying to be as efficient as I possibly can so I’m trying to zip the files in memory with the following code:

            //using AutoBatchUpdate to prevent errors
            public byte[] ZipIt(byte[] XMLBytes)
            {
                MemoryStream ms = new MemoryStream();
                StreamFile mf = new StreamFile(ms);

                try
                {               
                    ZipArchive zip = new ZipArchive(mf);

                    using (new AutoBatchUpdate(zip))
                    {
                        AbstractFile zipFile = zip.CreateFile(SourceFileName, true);
                        Stream stream = zipFile.OpenWrite(true);
                        using (stream)
                        {
                            stream.Write(XMLBytes, 0, XMLBytes.Length);
                            stream.Flush();
                        }
                    }
                }
                catch (Exception ex)
                {
                    throw new Exception(string.Format(“Failed to zip file with length: {0}\rReason: {1}”, XMLBytes.Length, ex.Message));
                }
                finally
                {
                    if (ms != null) ms.Close();               
                }

                return ms.ToArray();
            }
        }

    However, I’m getting the following errors from XCeed.Zip listed below whenever the stream object is being disposed.  This seems to be related to http://xceed.com/CS/forums/post/4890.aspx. I should mention that this occurs during heavy processing (1133 files in 3 1/2 minutes).

     Any help would be appreciated,

    Bill N

    Reason:
    Xceed.FileSystem.FileSystemInternalException: Missing ZipHandler in main
    table.
       at
    Xceed.Zip.ZipHandler.UpdateZipHandlerKey(ZipHandler handler, AbstractFile
    oldZipFile, AbstractFile newZipFile)
       at
    Xceed.Zip.ZipHandler.Flush(FileSystemEventsSession session)
       at
    Xceed.Zip.ZipHandler.Release(FileSystemEventsSession session)
       at
    Xceed.Zip.ZipHandler.ReleaseModify(FileSystemEventsSession session)
       at
    Xceed.Zip.ZipItemHandler.OnClosingWritingStreamEvent(Object sender, NotifyStreamArgs
    args)
       at
    Xceed.Utils.Streams.NotifyStream.OnClosingStream()
       at
    Xceed.Utils.Streams.NotifyStream.Dispose(Boolean disposing)
       at System.IO.Stream.Close()
       at
    System.IO.Stream.Dispose()
      

    Reason:
    System.ObjectDisposedException: Cannot access a disposed object.
    Object name: ‘ZipHandler’.
       at
    Xceed.Zip.ZipHandler.CheckIfDisposed()
       at
    Xceed.Zip.ZipItemHandler.OnClosingWritingStreamEvent(Object sender,
    NotifyStreamArgs args)
       at
    Xceed.Utils.Streams.NotifyStream.OnClosingStream()
       at
    Xceed.Utils.Streams.NotifyStream.Dispose(Boolean disposing)
       at System.IO.Stream.Close()
       at
    System.IO.Stream.Dispose()
     

    Reason:
    System.InvalidOperationException: Collection was modified after the
    enumerator was instantiated.
       at
    System.ThrowHelper.ThrowInvalidOperationException(ExceptionResource
    resource)
       at
    System.Collections.Generic.SortedList`2.SortedListValueEnumerator.MoveNext()
       at
    Xceed.Zip.ZipHandler.WriteLocalHeaders(FileSystemEventsSession session,
    BinaryWriter writer)
       at
    Xceed.Zip.ZipHandler.WriteZipToStream(FileSystemEventsSession session,
    BinaryWriter writer)
       at Xceed.Zip.ZipHandler.Flush(FileSystemEventsSession
    session)
       at
    Xceed.Zip.ZipHandler.Release(FileSystemEventsSession session)
       at Xceed.Zip.ZipHandler.ReleaseModify(FileSystemEventsSession
    session)
       at
    Xceed.Zip.ZipItemHandler.OnClosingWritingStreamEvent(Object sender,
    NotifyStreamArgs args)
       at Xceed.Utils.Streams.NotifyStream.OnClosingStream()
       at
    Xceed.Utils.Streams.NotifyStream.Dispose(Boolean disposing)
       at System.IO.Stream.Close()
       at
    System.IO.Stream.Dispose()

      

     

    Imported from legacy forums. Posted by Bill (had 7800 views)

    Diane [Xceed]
    Moderator
    Post count: 1353

    Hi Bill,

    Could you send us a sample project which demonstrates the issue so that we may investigate this problem? Please send it to support@xceed.com and include a link to this forum thread for reference. Thank you.

     

    Imported from legacy forums. Posted by Diane [Xceed] (had 490 views)

    User (Old forums)
    Member
    Post count: 23064

    Hello, 

    Has there been any headway made with this issue? I’m seeing similar behavior.

    Here is the offending code:

          StreamFile sfDocument = new StreamFile(m_msDocument);
          ZipArchive zaDocument = new ZipArchive(sfDocument);
          AbstractFolder afolder = zaDocument.GetFolder(ZIP_FOLDER);
          AbstractFile afile = afolder.GetFile(ZIP_FILE);
          Stream ms= afile.OpenWrite(true); 
          origDocument.Save(ms);
          ms.Close();

    I also saw the link that Bill posted and changed the code to use AutoBatchUpdate, however I’m getting all sorts of errors (the linked thread only mentions one) so I thought I would research a little more and found this thread. Here are some errors I’ve seen (we had another one but didn’t capture it, something about denied Access): 

    System.ObjectDisposedException: Cannot access a disposed object.

    Object name: ‘ZipHandler’.

       at Xceed.Zip.ZipHandler.CheckIfDisposed()

       at Xceed.Zip.ZipItemHandler.OpenRawRead(FileSystemEventsSession session)

       at Xceed.Zip.ZipItemHandler.MoveFromZipToTemp(FileSystemEventsSession session)

       at Xceed.Zip.ZipHandler.MoveFilesToKeep(FileSystemEventsSession session)

       at Xceed.Zip.ZipHandler.Flush(FileSystemEventsSession session)

       at Xceed.Zip.ZipHandler.Release(FileSystemEventsSession session)

       at Xceed.Zip.ZipHandler.ReleaseModify(FileSystemEventsSession session)

       at Xceed.Zip.ZipItemHandler.OnClosingWritingStreamEvent(Object sender, NotifyStreamArgs args)

       at Xceed.Utils.Streams.NotifyStream.OnClosingStream()

       at Xceed.Utils.Streams.NotifyStream.Dispose(Boolean disposing)

       at System.IO.Stream.Close()

     

    Xceed.FileSystem.FileSystemInternalException: Missing ZipHandler in main table.

       at Xceed.Zip.ZipHandler.UpdateZipHandlerKey(ZipHandler handler, AbstractFile oldZipFile, AbstractFile newZipFile)

       at Xceed.Zip.ZipHandler.Flush(FileSystemEventsSession session)

       at Xceed.Zip.ZipHandler.Release(FileSystemEventsSession session)

       at Xceed.Zip.ZipHandler.ReleaseModify(FileSystemEventsSession session)

       at Xceed.Zip.ZipItemHandler.OnClosingWritingStreamEvent(Object sender, NotifyStreamArgs args)

       at Xceed.Utils.Streams.NotifyStream.OnClosingStream()

       at Xceed.Utils.Streams.NotifyStream.Dispose(Boolean disposing)

       at System.IO.Stream.Close()

     

    Xceed.FileSystem.ItemDoesNotExistException: Cannot perform the requested operation on an item that does not exist.

    Type: Xceed.FileSystem.DiskFile

    FullName: C:\Documents and Settings\user\Local Settings\Temp\59a29cfe-7899-45f1-98b8-0e268055a7c2.tmp

       at Xceed.FileSystem.AbstractFile.OpenRead(FileSystemEvents events, Object userData, FileShare share)

       at Xceed.FileSystem.AbstractFile.OpenRead()

       at Xceed.Zip.ZipItemHandler.OpenRawRead(FileSystemEventsSession session)

       at Xceed.Zip.ZipItemHandler.WriteData(FileSystemEventsSession session, Stream stream)

       at Xceed.Zip.ZipItemHandler.WriteLocalHeader(FileSystemEventsSession session, ZipStream stream)

       at Xceed.Zip.ZipHandler.WriteLocalHeaders(FileSystemEventsSession session, BinaryWriter writer)

       at Xceed.Zip.ZipHandler.WriteZipToStream(FileSystemEventsSession session, BinaryWriter writer)

       at Xceed.Zip.ZipHandler.Flush(FileSystemEventsSession session)

       at Xceed.Zip.ZipHandler.Release(FileSystemEventsSession session)

       at Xceed.Zip.ZipHandler.ReleaseModify(FileSystemEventsSession session)

       at Xceed.Zip.ZipItemHandler.OnClosingWritingStreamEvent(Object sender, NotifyStreamArgs args)

       at Xceed.Utils.Streams.NotifyStream.OnClosingStream()

       at Xceed.Utils.Streams.NotifyStream.Dispose(Boolean disposing)

       at System.IO.Stream.Close()

    Xceed.Zip.ZipIOException: An IO exception occurred while reading from or writing to the zip file.
    Zip file: SFF21621962:\SF23399238 —> Xceed.FileSystem.FileSystemIOException: The file item could not be opened for reading.
    Type: Xceed.FileSystem.DiskFile
    FullName: d:\Profiles\user\Local Settings\Temp\486edcf9-533c-4a5e-bf11-02cc003f8b41.tmp —> System.IO.IOException: The process cannot access the file ‘d:\Profiles\user\Local Settings\Temp\486edcf9-533c-4a5e-bf11-02cc003f8b41.tmp’ because it is being used by another process.
       at System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath)
       at System.IO.FileStream.Init(String path, FileMode mode, FileAccess access, Int32 rights, Boolean useRights, FileShare share, Int32 bufferSize, FileOptions options, SECURITY_ATTRIBUTES secAttrs, String msgPath, Boolean bFromProxy)
       at System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share)
       at System.IO.FileInfo.Open(FileMode mode, FileAccess access, FileShare share)
       at Xceed.FileSystem.DiskFile.DoOpenRead(FileSystemEventsSession session, FileShare share)
       — End of inner exception stack trace —
       at Xceed.FileSystem.AbstractFile.OpenRead(FileSystemEvents events, Object userData, FileShare share)
       at Xceed.FileSystem.AbstractFile.OpenRead()
       at Xceed.Zip.ZipItemHandler.OpenRawRead(FileSystemEventsSession session)
       — End of inner exception stack trace —
       at Xceed.Zip.ZipItemHandler.OpenRawRead(FileSystemEventsSession session)
       at Xceed.Zip.ZipItemHandler.WriteData(FileSystemEventsSession session, Stream stream)
       at Xceed.Zip.ZipItemHandler.WriteLocalHeader(FileSystemEventsSession session, ZipStream stream)
       at Xceed.Zip.ZipHandler.WriteLocalHeaders(FileSystemEventsSession session, BinaryWriter writer)
       at Xceed.Zip.ZipHandler.WriteZipToStream(FileSystemEventsSession session, BinaryWriter writer)
       at Xceed.Zip.ZipHandler.Flush(FileSystemEventsSession session)
       at Xceed.Zip.ZipHandler.Release(FileSystemEventsSession session)
       at Xceed.Zip.ZipHandler.ReleaseModify(FileSystemEventsSession session)
       at Xceed.Zip.ZipItemHandler.OnClosingWritingStreamEvent(Object sender, NotifyStreamArgs args)
       at Xceed.Utils.Streams.NotifyStream.OnClosingStream()
       at Xceed.Utils.Streams.NotifyStream.Dispose(Boolean disposing)
       at System.IO.Stream.Close()

    One last thing worth mentioning is that we didn’t see any errors during initial testing, but now they seem to be cropping up pretty often. Any thoughts would be appreciated.

    Thanks,
    -Pete

    Imported from legacy forums. Posted by Pete (had 555 views)

    User (Old forums)
    Member
    Post count: 23064

    Hi Pete,

    As Diane said to Bill,  could you send us a sample project which demonstrates the issue so that we may investigate this problem? Please send it to support@xceed.com and include a link to this forum thread for reference. Thank you.

    Best regards,

    Imported from legacy forums. Posted by Ghislain (had 477 views)

    User (Old forums)
    Member
    Post count: 23064

    Hi,

    Thanks for the response. Unfortunately I am not able to send a sample project. I actually made a minimal project that ran that specific code, but could not reproduce it on my machine even when running it 2000 times. However it was easily reproducable on 2 other machines. There seems to be something machine-specific that causes it, but I did not have time to research it more. We ended up bypassing that code and doing the unzipping/rezipping in the file system (still using Xceed methods), which had no issues.

    Sorry I couldn’t be more help,
    -Pete

    Imported from legacy forums. Posted by Pete (had 401 views)

    User (Old forums)
    Member
    Post count: 23064

    Hi,

    the ‘something specific’ could not be identified?  Operating system, service pack?  If ever you can come back here with an idea, we will be glad to help!

     

    Imported from legacy forums. Posted by Ghislain (had 735 views)

    User (Old forums)
    Member
    Post count: 23064

    I had a similar issue and found a solution. The problem is that zipFile can get GC’d before the stream created from it is closed/disposed. zipFile’s finalizer disposes an internal ZipHandler object associated with it. When the steam is closed or disposed it calls CheckIfDisposed() on the same ZipHandler, which throws an ObjectDisposedException if zipFile’s finalizer got there first. The solution is to use GC.KeepAlive() on zipFile to prevent it from being prematurely GC’d. In most cases it probably doesn’t matter, but if the code is running on a machine with memory pressures, GC will run very frequently and this problem is inclined to surface. Differences in how the code is jitted may also result in inconsistent behavior.

    This is a design mistake on Xceed’s part. The proper working of their zip streams depend on the lifetime of a specific type of object but they provide no way to control the life of the object.

    Have I saved your life? Send your story to: zimberto@gmail.com [:)]

    Imported from legacy forums. Posted by Zim (had 2291 views)

Viewing 7 posts - 1 through 7 (of 7 total)
  • You must be logged in to reply to this topic.