[
  {
    "Id": "428053",
    "ThreadId": "208496",
    "Html": "<p>Dino,</p>\r\n<p>I'm experiencing an issue when performing two independent operations. The snippet at below contains two blocks, each including an invocation of the <em>Save </em>method. Both are totally unrelated:</p>\r\n<ul>\r\n<li>The first one adds a directory &quot;XX&quot; to the ZIP file</li>\r\n<li>The second one updates paths of all entries within the &quot;Download&quot; folder, including the folder itself.</li>\r\n</ul>\r\n<p>Now, if I comment out <strong>either </strong>the first part or the second, the code runs through without any errors and the ZIP file is properly updated. However, the snippet as it is below, fails with a NullReferenceException on the second save invocation:</p>\r\n<p><em>System.NullReferenceException : Object reference not set to an instance of an object.<br>&nbsp;&nbsp; &nbsp;at Ionic.Zip.SharedUtilities.ReadWithRetry(Stream s, Byte[] buffer, Int32 offset, Int32 count, String FileName)<br>&nbsp;&nbsp; &nbsp;at Ionic.Zip.ZipEntry._WriteEntryData(Stream s)<br>&nbsp;&nbsp; &nbsp;at Ionic.Zip.ZipEntry.Write(Stream s)<br>&nbsp;&nbsp; &nbsp;at Ionic.Zip.ZipFile.Save()</em></p>\r\n<p>Now, if I switch part 1 and 2 (first do the renaming and save, then add the directory and save), this again does not cause an exception. And the code also works if I only save once at the end of both blocks (add directory, rename, save). Any ideas what's happening here?</p>\r\n<p>Thanks for your advice</p>\r\n<p>Philipp</p>\r\n<p>&nbsp;</p>\r\n<p>&nbsp;</p>\r\n<div style=\"color:Black;background-color:White\">\r\n<pre>    [Test]\r\n    <span style=\"color:Blue\">public</span> <span style=\"color:Blue\">void</span> DummyTest()\r\n    {\r\n      <span style=\"color:Blue\">var</span> zip = Provider.NodeRepository.ZipFile;\r\n      <span style=\"color:Blue\">var</span> entries = zip.Entries.Where(e =&gt; e.FileName.Contains(<span style=\"color:#A31515\">&quot;Download&quot;</span>)).ToArray();\r\n\r\n      <span style=\"color:Green\">//PART1 - Add directory and save</span>\r\n      zip.AddDirectoryByName(<span style=\"color:#A31515\">&quot;XX&quot;</span>);\r\n      zip.Save();\r\n      \r\n      <span style=\"color:Green\">//PART2 - Rename paths (not related to XX directory from above) and save</span>\r\n      <span style=\"color:Blue\">foreach</span> (<span style=\"color:Blue\">var</span> zipEntry <span style=\"color:Blue\">in</span> entries)\r\n      {\r\n        zipEntry.FileName = zipEntry.FileName.Replace(<span style=\"color:#A31515\">&quot;Download&quot;</span>, <span style=\"color:#A31515\">&quot;Download2&quot;</span>);\r\n      }\r\n      zip.Save();<br>  &nbsp;}\r\n</pre>\r\n</div>\r\n<p>&nbsp;</p>",
    "PostedDate": "2010-04-06T14:52:46.967-07:00",
    "UserRole": null,
    "MarkedAsAnswerDate": null
  },
  {
    "Id": "428239",
    "ThreadId": "208496",
    "Html": "<p>I did some more debugging, and it might have to do that the _Source property is <strong>None </strong>(sorry, mistakenly wrote null first) on the second save, which prevents the entry to be saved without restreaming:</p>\r\n<p>&nbsp;</p>\r\n<div style=\"color:Black;background-color:White\">\r\n<pre><span style=\"color:Blue\">if</span> (_Source == ZipEntrySource.ZipFile &amp;&amp; !_restreamRequiredOnSave)\r\n{\r\n  CopyThroughOneEntry(s);\r\n  <span style=\"color:Blue\">return</span>;\r\n}\r\n\r\n</pre>\r\n</div>\r\n<p>&nbsp;</p>\r\n<p>If I only save once, the _Source property of the renamed file entry is set, and the the <em>CopyThroughOneEntry </em>method is invoked accordingly.</p>\r\n<p><em><br></em></p>\r\n<p>&nbsp;</p>",
    "PostedDate": "2010-04-07T04:22:46.97-07:00",
    "UserRole": null,
    "MarkedAsAnswerDate": null
  },
  {
    "Id": "431627",
    "ThreadId": "208496",
    "Html": "<p>First of all sorry for bumping the thread, but I'm a bit lost on this one, as it is a severe show stopper (recreating the ZipFile after every safe is not an option). For now, I got my code working by maintaining a custom build of your code, where I modified the ZipEntry class like this:</p>\r\n<p>&nbsp;</p>\r\n<pre><span style=\"color:Blue\">if</span> ( (_Source == ZipEntrySource.ZipFile || source == ZipEntrySource.None) &amp;&amp; !_restreamRequiredOnSave)<br>{<br>  CopyThroughOneEntry(s);<br>  <span style=\"color:Blue\">return</span>;<br>}<br><br><br></pre>\r\n<p>...but I don't have any ideas about potential side effects (and also don't know whether a simple fix will be possible in the mid future). So any advice on how to handle this is highly appreaciated.</p>\r\n<p>Cheers,</p>\r\n<p>Philipp</p>",
    "PostedDate": "2010-04-15T12:44:08.567-07:00",
    "UserRole": null,
    "MarkedAsAnswerDate": null
  },
  {
    "Id": "432675",
    "ThreadId": "208496",
    "Html": "<p>Another side effect when trying to open an item once it has been created in the InternalOpenReader method, which caused an exception because once again, the source was None:</p>\r\n\r\n<p>\r\n<pre>\r\nif (this._Source != ZipEntrySource.ZipFile)<br>\r\n       throw new BadStateException(&quot;You must call ZipFile.Save before calling OpenReader.&quot;);\r\n</pre>\r\n</p>\r\n\r\n\r\n<p>Given the the Save itself caused the issue (setting the _Source to _None), the error message itself is problematic, too. I assume it's this method that causes the issue:</p>\r\n\r\n<p>\r\n<pre>\r\n        internal void NotifySaveComplete()\r\n        {\r\n            _Encryption_FromZipFile = _Encryption;\r\n            _CompressionMethod_FromZipFile = _CompressionMethod;\r\n            _restreamRequiredOnSave = false;\r\n            _metadataChanged = false;\r\n            _Source = ZipEntrySource.None;\r\n        }\r\n</pre>\r\n</p>",
    "PostedDate": "2010-04-19T05:05:50.617-07:00",
    "UserRole": null,
    "MarkedAsAnswerDate": null
  }
]