- Notifications
You must be signed in to change notification settings - Fork1.6k
Open
Description
Type of issue
Missing information
Description
ZipArchive
currently does not allow concurrent entry creation, and doing so results inIOException
being thrown at run time. For example:
usingSystem.IO.Compression;usingMemoryStreammemoryStream=new();usingZipArchivearchive=new(memoryStream,ZipArchiveMode.Create);Task[]tasks=newTask[32];for(inti=0;i<tasks.Length;i++){tasks[i]=CreateEntryAsync(archive);}awaitTask.WhenAll(tasks).ConfigureAwait(false);staticasyncTaskCreateEntryAsync(ZipArchivezipArchive){ZipArchiveEntryentry=zipArchive.CreateEntry(Path.GetRandomFileName());usingStreamstream=entry.Open();awaitTask.Delay(100);// Simulate asynchronous write}
throws:
Unhandled exception. System.IO.IOException: Entries cannot be created while previously created entries are still open. at System.IO.Compression.ZipArchive.AcquireArchiveStream(ZipArchiveEntry entry) at System.IO.Compression.ZipArchive.DoCreateEntry(String entryName, Nullable`1 compressionLevel) at System.IO.Compression.ZipArchive.CreateEntry(String entryName) at Program.<<Main>$>g__CreateEntryAsync|0_0(ZipArchive zipArchive) in Program.cs:line 14 at Program.<Main>$(String[] args) in Program.cs:line 10 at Program.<Main>(String[] args)
While the limitation itself is understandable, I think it should be pointed out by the documentation. Right now neither the Exceptions section nor the Remarks section mentions this behavior.
Page URL
Content source URL
https://github.com/dotnet/dotnet-api-docs/blob/main/xml/System.IO.Compression/ZipArchive.xml
Document Version Independent Id
6edb630b-4e65-bdf8-8efd-cb5974682887
Platform Id
5bc53832-8985-3cc1-93b6-79225f7fb140