Home Forums .NET libraries Xceed Zip & Real-Time Zip for .NET Cannot access a disposed object. Object name: ‘ZipHandler’.

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

    I have a method that abstracts the compression process and returns me a byte array that is then base64 encoded and uploaded. I had the method implemented originally with memory streams and not temp files to save on disk IO. We started getting the error in the title in some cases so I transitioned the code to use a temp file. The error persists. It is not every machine and the reproducibility is only on those machines. The problem appears to be in the xceed code. The code for the method is below. Below the code is a log snippet from a machine I can consistently reproduce the error on. The error occurs every time in the catch (ObjectDisposedException ode) block. How do I resolve this error or better log/debug it on the client machines?

    <code>
    public static byte[] XceedCompress( byte[] Output, string Filename, string InternalFilename )
    {
    string tempFile = System.IO.Path.GetTempFileName();
    DiskFile dfZip = new DiskFile(tempFile);
    ZippedFile mf = null;
    ZipArchive zip = null;
    byte[] byt = null;

    try
    {
    Log.Verbose(“XceedCompress”);
    Log.Verbose(string.Format(“Output size: {0}, FileName: \”{1}\”, Output: \”{2}\””,
    Output.Length, Filename, Encoding.Default.GetString( Output)));
    if (!dfZip.Exists)
    {
    Log.Verbose(string.Format(“Zip file \”{0}\” does not exist.”, dfZip.FullName)); dfZip.Create();
    }
    zip = new ZipArchive(dfZip);
    Log.Verbose(“Created new archive”);
    zip.DefaultCompressionMethod = Xceed.Compression.CompressionMethod.Deflated;

    mf = (ZippedFile)zip.GetFile(InternalFilename);
    Log.Verbose(“Got zip file”);

    if (!mf.Exists)
    {
    mf.Create();
    Log.Verbose(“created zip file”);
    }
    try
    {
    using (Stream s = mf.OpenWrite(true))
    {
    s.Write(Output, 0, Output.Length);
    Log.Verbose(“wrote stream”);
    }
    }
    catch (ObjectDisposedException ode)
    {
    Log.Verbose(“ObjectDisposed”);
    Log.Verbose(ode.Message);
    }
    Log.Verbose(“Before get bytes”);
    Log.Verbose(“DiskFile open read stream is: ” + (string)(dfZip.OpenRead() == null ? ” Null” : “Not Null”));
    // get byts of zip file to return
    using (Stream s = dfZip.OpenRead())
    {
    byt = new byte[(int)s.Length];
    s.Read(byt, 0, (int)s.Length);
    Log.Verbose(“got bytes”);
    }
    File.Delete(tempFile);
    }
    catch (Exception ex)
    {
    Log.Verbose(“XceedCompress catch block”);
    Log.Verbose(ex.Message);
    }
    finally
    {
    dfZip = null;
    mf = null;
    zip = null;
    }
    Log.Verbose(“returning zip byte array”);
    return byt;
    }
    </code>
    <log>
    1/15/2008 12:55:17 PM [V] XceedCompress
    1/15/2008 12:55:17 PM [V] Output size: 413973, FileName: “OrlandoMendoza_01_15_2008-12_55_17.jcn”, Output: “[File contents prior to compression omitted]”
    1/15/2008 12:55:17 PM [V] Created new archive
    1/15/2008 12:55:17 PM [V] Got zip file
    1/15/2008 12:55:17 PM [V] created zip file
    1/15/2008 12:55:17 PM [V] wrote stream
    1/15/2008 12:55:17 PM [V] ObjectDisposed
    1/15/2008 12:55:17 PM [V] Cannot access a disposed object. Object name: ‘ZipHandler’.
    1/15/2008 12:55:17 PM [V] Before get bytes
    1/15/2008 12:55:17 PM [V] DiskFile open read stream is: Not Null
    1/15/2008 12:55:17 PM [V] got bytes
    1/15/2008 12:55:17 PM [V] XceedCompress catch block
    1/15/2008 12:55:17 PM [V] The process cannot access the file ‘C:\Documents and Settings\LBM\Local Settings\Temp\tmpA5BB.tmp’ because it is being used by another process.
    1/15/2008 12:55:17 PM [V] returning zip byte array
    </log>

    Imported from legacy forums. Posted by Wayne (had 5199 views)

    Xceed Support
    Member
    Post count: 5658

    We have an internal mecanism managing references to items inside the ZipArchive, which is named ZipHandler. Those are static references to items in ZipArchive which are cleaned only when a ZippedFile or ZippedFolder destructor are called.

    Does it occurs the first time you run the snippet, or after several times?

    It may be caused by a destructor being executed while you are accessing the stream the next time you run this code.

    Imported from legacy forums. Posted by Chris [Xceed] (had 531 views)

    User (Old forums)
    Member
    Post count: 23064

    This happens no matter when the code is called from the first to subsquent times. Like I mentioned earlier this only occurs on some client machines. Look forward to any suggestions on how to fix or work around this.

    Imported from legacy forums. Posted by Wayne (had 466 views)

    Xceed Support
    Member
    Post count: 5658

    We created a bug report for this. As soon as we have updates concerning this case, we post the information here.

    Imported from legacy forums. Posted by CharlesB (had 439 views)

    Xceed Support
    Member
    Post count: 5658

    We tried to reproduce with the latest build on Vista x86, .NET 3.5 with your test code without any success. Would it be possible to get more informations on the systems where the problem occurs? (OS version, .NET framework)

    Imported from legacy forums. Posted by Chris [Xceed] (had 3805 views)

    Xceed Support
    Member
    Post count: 5658

    From an other user: using the AutoBatchUpdate solved the problem:

    Original code:
            try {
                ZipArchive zip = new ZipArchive(new DiskFile(filename));
                AbstractFile calibrationFile =
    zip.CreateFile(“CalibrationData.xml”, true);
                Stream s = calibrationFile.OpenWrite(true);
                using (s) {
                    XmlSerializer x = new
    XmlSerializer(typeof(CalibrationData));
                    TextWriter writerText = new StreamWriter(s);
                    x.Serialize(writerText, data);
                }
            }
            catch (Exception ex) {
                MessageBox.Show(ex.Message);
            }

    New code:
            try {
                ZipArchive zip = new ZipArchive(new DiskFile(filename));
                using (new AutoBatchUpdate(zip)) {
                    AbstractFile calibrationFile =
    zip.CreateFile(“CalibrationData.xml”, true);
                    Stream s = calibrationFile.OpenWrite(true);
                    using (s) {
                        XmlSerializer x = new
    XmlSerializer(typeof(CalibrationData));
                        TextWriter writerText = new StreamWriter(s);
                        x.Serialize(writerText, data);
                    }
                }
            }
            catch (Exception ex) {
                MessageBox.Show(ex.Message);
            }

    Imported from legacy forums. Posted by CharlesB (had 2793 views)

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