Open
Description
Type of issue
Missing information
Description
ZipArchive
currently does not allow concurrent entry creation, and doing so results in IOException
being thrown at run time. For example:
using System.IO.Compression;
using MemoryStream memoryStream = new();
using ZipArchive archive = new(memoryStream, ZipArchiveMode.Create);
Task[] tasks = new Task[32];
for (int i = 0; i < tasks.Length; i++)
{
tasks[i] = CreateEntryAsync(archive);
}
await Task.WhenAll(tasks).ConfigureAwait(false);
static async Task CreateEntryAsync(ZipArchive zipArchive)
{
ZipArchiveEntry entry = zipArchive.CreateEntry(Path.GetRandomFileName());
using Stream stream = entry.Open();
await Task.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