Problem with ICSharpCode.SharpZipLib.Zip

  • Thread starter Thread starter Maxim Kazitov
  • Start date Start date
M

Maxim Kazitov

Hi,

My application open 5 ZIP files and read Entry from all 5 files.
and first 5 times all is fine,
but then I have following Exception :

Exception: System.ObjectDisposedException
Message: Cannot access a closed file.
Source: mscorlib
at System.IO.__Error.FileNotOpen()
at System.IO.FileStream.Seek(Int64 offset, SeekOrigin origin)
at ICSharpCode.SharpZipLib.Zip.ZipFile.CheckLocalHeader(ZipEntry entry)
at ICSharpCode.SharpZipLib.Zip.ZipFile.GetInputStream(Int32 entryIndex)
at ICSharpCode.SharpZipLib.Zip.ZipFile.GetInputStream(ZipEntry entry)

=========================================================

But I don't close any files.

Does any body know any work around ?
 
Maxim said:
Hi,

My application open 5 ZIP files and read Entry from all 5 files.
and first 5 times all is fine,

Are you closing the stream obtained form ZipEntry.GetInputStream?
Don't do it. This will close the whole archive.

bye
Rob
 
ZipFile.GetInputStream return InflaterInputStream.

InflaterInputStream.Close() - close baseStream in ZipFile.

Some .Net Objects, for Example XPathDocument close stream after reading.

So,

if you comment stream closing in (InflaterInputStream.cs) problem go on
:

-------------------------------
public override void Close()
{
//baseInputStream.Close();
}
--------------------------------

I resolve this problem using temporary stream :

Stream oStream = oZipFile.GetInputStream(oEntry);
String sXml = new StreamReader(oStream).ReadToEnd();
MemoryStream oSMem = new MemoryStream(sXml.Length);
StreamWriter oSWriter = new StreamWriter(oSMem);
oSWriter.Write(sXml);
oSWriter.Flush();
oSMem.Seek(0, SeekOrigin.Begin);

XPathDocument oDoc = new XPathDocument(oSMem);
 
Maxim Kazitov said:
ZipFile.GetInputStream return InflaterInputStream.

InflaterInputStream.Close() - close baseStream in ZipFile.

Some .Net Objects, for Example XPathDocument close stream after reading.

So,

if you comment stream closing in (InflaterInputStream.cs) problem go on
:

-------------------------------
public override void Close()
{
//baseInputStream.Close();
}
--------------------------------

I resolve this problem using temporary stream :

Stream oStream = oZipFile.GetInputStream(oEntry);
String sXml = new StreamReader(oStream).ReadToEnd();
MemoryStream oSMem = new MemoryStream(sXml.Length);
StreamWriter oSWriter = new StreamWriter(oSMem);
oSWriter.Write(sXml);
oSWriter.Flush();
oSMem.Seek(0, SeekOrigin.Begin);

XPathDocument oDoc = new XPathDocument(oSMem);

You'd better hope that the XML is in UTF-8 with that method :)
(It would be better to avoid doing the character conversion at all.)

One alternative is to use a proxying stream which doesn't forward the
Close request.

See http://www.pobox.com/~skeet/csharp/miscutil
 
Back
Top