Hello everybody,
I started using DotNetZip in my application but I have problem when I want to use a zip file twice within my application. For example, first I read my zip file and display the content in my application.
```
using (ZipFile zip = ZipFile.Read(zipPath))
{
...
}
```
Then later, I want to extract the same zip file, therefore I use the same code above and read the zip file into 'zip'. But then I receive an OverflowException:
```
Zip File Error: Cannot read that as a ZipFileSystem.OverflowException: overflow while creating filename
at Ionic.Zip.ZipEntry.CopyHelper.AppendCopyToFileName(String f)
at Ionic.Zip.ZipEntry.ReadDirEntry(ZipFile zf, Dictionary`2 previouslySeen)
at Ionic.Zip.ZipFile.ReadCentralDirectory(ZipFile zf)
at Ionic.Zip.ZipFile.ReadIntoInstance(ZipFile zf) ; File
```
When I close the application and start again, I can do the first step again but not the second. This happens to me every time I start reading to a zip file the second time.
Any idea why I get this exception? Thanks in advance.
Comments: ** Comment from web user: Igulator **
I found the cause and a workaround for this problem.
Ionic.Zip.ZipEntry.CopyHelper.AppendCopyToFileName is called when duplicate filenames are present in the zip file, and attaches "(copy 1)", "(copy 2)" ... to the filenames. I guess to prevent infinite loops there is a hard limit checked at the beginning of the method:
```
callCount++;
if (callCount > 25)
throw new OverflowException("overflow while creating filename");
```
But there is a bug: callCount is a static variable which is never reset, so after you opened zip files with 25 duplicate entries in total, opening _any_ other zip file with at least one duplicate file throws this exception.
A workaround is to reset this counter via reflection, for example:
```
Type copyHelper = typeof(ZipEntry).Assembly.GetTypes().FirstOrDefault(t => t.FullName == "Ionic.Zip.ZipEntry+CopyHelper");
if (copyHelper != null)
{
FieldInfo callCount = copyHelper.GetField("callCount", BindingFlags.Static | BindingFlags.NonPublic);
if (callCount != null)
callCount.SetValue(null, 0);
}
```