dotnet / dotnet/dotnet-api-docs
`ZipArchive` should document limitation on concurrent entry creation
- Dominant language
- C#
- Stars
- 949
- Forks
- 1.7k
- Avg merge
- 3d 27m
- Merged PRs (30d)
- 49
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:
```cs
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.<$>g__CreateEntryAsync|0_0(ZipArchive zipArchive) in Program.cs:line 14
at Program.$(String[] args) in Program.cs:line 10
at Program.(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
https://learn.microsoft.com/en-us/dotnet/api/system.io.compression.ziparchive.createentry?view=net-9.0
### 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
### Article author
@dotnet-bot
Contributor guide
Assessment
This issue has not been assessed yet.