Feb 26, 2010 at 7:17 PM
Edited Feb 26, 2010 at 7:27 PM
The problem is that internally the set of entries is stored as a Dictionary<String,ZipEntry>. The string is the entry name. This allows quick access using the string indexer.
Renaming an entry - setting the FileName on the entry - causes the entry to be removed and then re-added into the Dictionary. This modifies the collection and prevents the foreach from continuing.
You have the workaround I have to you. Another possible workaround is to copy the list of entries and enumerate through the copy.
A possible solution is for DotNetZip to return a copy of the List for the foreach loop. With the fix you could do "foreach(var entry in zip) ..." and get the expected results, even if you rename an entry within the loop. The problem
is that for large zip files, doing a copy for a foreach loop that does not involve renaming any entries, would be unnecessarily slow, and memory hungry. So at this point I'm not sure I want to make the change.
For now I am leaning toward making a document change that describes this limitation and the workarounds.