[
  {
    "Id": "497183",
    "ThreadId": "228213",
    "Html": "<p>I have the following code on v1.9:</p>\r\n<div style=\"color:black;background-color:white\">\r\n<pre>\r\n<span style=\"color:blue\">if</span>(StosZipFile.ContainsEntry(StosFileName))\r\n{\r\n    ZipEntry entry = StosZipFile[StosFileName];\r\n    Byte[] buffer = <span style=\"color:blue\">new</span> Byte[entry.UncompressedSize];\r\n    MemoryStream memStream = <span style=\"color:blue\">new</span> MemoryStream(buffer);\r\n \r\n    <span style=\"color:green\">//Fails with &quot;Cannot access a closed stream</span>\r\n    entry.Extract(memStream);\r\n\r\n    ...\r\n}<br><br>I'm hoping I'm missing something obvious, but no matter how I create the memory stream I get that error.&nbsp; I can write my own byte array to the stream without problems.<br><br>Any ideas?\r\n\r\n\r\n\r\n\r\n</pre>\r\n</div>",
    "PostedDate": "2010-09-22T13:04:19.98-07:00",
    "UserRole": null,
    "MarkedAsAnswerDate": null
  },
  {
    "Id": "497188",
    "ThreadId": "228213",
    "Html": "<p>I also tried passing the Uncompressed size directly to the MemoryStream constructor.</p>",
    "PostedDate": "2010-09-22T13:06:05.54-07:00",
    "UserRole": null,
    "MarkedAsAnswerDate": null
  },
  {
    "Id": "497196",
    "ThreadId": "228213",
    "Html": "<p>Argh... nevermind.&nbsp; The problem is that I closed the stream used to load the ZipFile in a completely different function:</p>\r\n<p>\r\n<div style=\"color:black;background-color:white\">\r\n<pre>Stream responseStream = response.GetResponseStream();\r\n\r\nByte[] buffer = Global.ReadToBuffer(responseStream, response.ContentLength);\r\n\r\nMemoryStream memStream = <span style=\"color:blue\">new</span> MemoryStream(buffer);\r\n\r\nzipFile = ZipFile.Read(memStream);\r\n\r\nresponseStream.Close();\r\n<br>//Problem, ZipFile takes a reference and expects it to remain open<br>memStream.Close();\r\n</pre>\r\n</div>\r\n</p>\r\n<p>How can I know when it is OK to close the memory stream if the ZipFile is going to hold a reference to it?&nbsp; Can we ask the ZipFile to make a copy of the data instead?</p>",
    "PostedDate": "2010-09-22T13:17:24.623-07:00",
    "UserRole": null,
    "MarkedAsAnswerDate": null
  },
  {
    "Id": "497294",
    "ThreadId": "228213",
    "Html": "You should reference the ZipFile within a using clause.  This is not optional.  See the documentation on the ZipFile object for an explanation.  The examples in the documentation show what this looks like.  (or look at the test code in the DotNetZip source release) The MemoryStream can be closed after the ZipFile goes out of the using scope. Actually, you can use the MemoryStream within its own using clause, too. It's good form to use &quot;using&quot; with streams. ",
    "PostedDate": "2010-09-22T17:39:49.253-07:00",
    "UserRole": null,
    "MarkedAsAnswerDate": null
  }
]