Skip to content

Document ZipArchive.CreateAsync eager loading breaking change for .NET 11 - #51452

Merged
gewarren merged 4 commits into
mainfrom
copilot/fix-ziparchive-createasync-issue
Feb 4, 2026
Merged

gewarren merged 4 commits into
mainfrom
copilot/fix-ziparchive-createasync-issue

Conversation

Copilot AI commented Feb 3, 2026 •

Copy link
Copy Markdown
Contributor

Documents the behavioral change in .NET 11 Preview 1 where ZipArchive.CreateAsync eagerly loads all zip archive entries during the method call to prevent synchronous reads when accessing the .Entries property.

Changes

  • New article: core-libraries/11/ziparchive-createasync-eager-load.md
    • Documents timing shift: InvalidDataException for malformed entries now thrown in CreateAsync instead of .Entries access
    • Explains rationale: avoids blocking reads on async-only streams (e.g., network streams)
    • Provides exception handling guidance
  • TOC and index updates: Added entry to .NET 11 breaking changes

Impact

// Before: exception deferred to Entries access
var archive = await ZipArchive.CreateAsync(stream, ZipArchiveMode.Read);
var entries = archive.Entries; // May throw InvalidDataException here

// After: exception surfaces immediately
var archive = await ZipArchive.CreateAsync(stream, ZipArchiveMode.Read); // Throws here
var entries = archive.Entries; // No I/O, no exceptions

Developers should wrap CreateAsync calls in try-catch for InvalidDataException.

References: dotnet/runtime#121938, dotnet/runtime#121624

Original prompt

This section details on the original issue you should resolve

<issue_title>[Breaking change]: ZipArchive.CrateAsync eagerly loads all zip archive entries</issue_title>
<issue_description>### [Breaking change]: ZipArchive.CrateAsync eagerly loads all zip archive entries, potentially throwing if central directory is malformed.

Description

Starting in .NET 11 Preview 1, the behavior of the System.IO.Compression.ZipArchive class has been updated to improve consistency in handling asynchronous streams. Specifically, in order to avoid synchronous reads on the stream when accessing .Entries property of ZipArchive, the list of entries is read during the CreateAsync method call. This change aligns with the approved API design and ensures that asynchronous operations are handled correctly.

Version

.NET 11 Preview 1

Previous behavior

Previously, when working with a ZipArchive created using CreateAsync, accessing the .Entries property could result in a synchronous (blocking) read operation being performed. This behavior was inconsistent with the asynchronous nature of the CreateAsync method.

Example:

using System.IO;
using System.IO.Compression;
using System.Threading.Tasks;

var stream = new FileStream("malformed.zip");
var archive = await ZipArchive.CreateAsync(stream, ZipArchiveMode.Read);

// This call performs synchronous reads on the stream, and may throw if the file entries in are malformed
// or if the underlying stream does not allow synchronous reads.
var entries = archive.Entries; 

New behavior

With the updated behavior, the central directory of the zip archive is read (asynchronously) as part of the ZipArchive.CreateAsync method. Any exceptions related to the inability to list the zip archive entries are now thrown during the CreateAsync method call. Later access to .Entries does not perform any read operations on the underlying stream.

Example:

using System.IO;
using System.IO.Compression;
using System.Threading.Tasks;

var stream = new MemoryStream();

// This call eagerly loads the zip archive entries, surfacing any exception when parsing the file headers.
var archive = await ZipArchive.CreateAsync(stream, ZipArchiveMode.Create, leaveOpen: true);

// Accessing `.Entries` no longer throws an exception, as the issue is surfaced during `CreateAsync`.
var entries = archive.Entries; // No exception

Type of breaking change

  • Behavioral change: Existing binaries might behave differently at runtime.

Reason for change

This change was introduced to improve the consistency and reliability of the ZipArchive API when working with asynchronous streams. This aligns with the approved API design and avoids unexpected synchronous/blocking reads when accessing .Entries.

Recommended action

Developers should ensure that InvalidDataException thrown from ZipArchive.CreateAsync is correctly handled. This exception has already been thrown in previous .NET versions e.g. in cases when zip central directory cannot be found.

Affected APIs

  • System.IO.Compression.ZipArchive.CreateAsync(Stream, ZipArchiveMode, bool)
  • System.IO.Compression.ZipArchive.Entries

Additional information

This change was introduced in dotnet/runtime#121938 and addresses issues raised in dotnet/runtime#121624. For more details on the API design discussion, see this comment.</issue_description>

Comments on the Issue (you are @copilot in this section)


💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.


Internal previews

📄 File 🔗 Preview link
docs/core/compatibility/11.md Breaking changes in .NET 11
docs/core/compatibility/core-libraries/11/ziparchive-createasync-eager-load.md ZipArchive.CreateAsync eagerly loads ZIP archive entries
docs/core/compatibility/toc.yml docs/core/compatibility/toc

Document the breaking change in .NET 11 Preview 1 where ZipArchive.CreateAsync
eagerly loads all zip archive entries to avoid synchronous reads on the stream.

- Add article documenting the behavioral change
- Update TOC to include the new article
- Add entry to .NET 11 breaking changes index
Copilot AI changed the title [WIP] Fix ZipArchive.CreateAsync eager loading of entries Document ZipArchive.CreateAsync eager loading breaking change for .NET 11 Feb 3, 2026
Copilot AI requested a review from gewarren February 3, 2026 21:31
@gewarren
gewarren marked this pull request as ready for review February 3, 2026 23:55
@gewarren
gewarren requested a review from a team as a code owner February 3, 2026 23:55
Copilot AI review requested due to automatic review settings February 3, 2026 23:55

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Documents a .NET 11 breaking change where ZipArchive.CreateAsync eagerly loads ZIP entries to avoid synchronous reads when accessing ZipArchive.Entries.

Changes:

  • Added a new breaking change article describing the eager-loading behavior and the exception timing shift.
  • Updated the .NET 11 breaking changes index to include the new entry.
  • Updated the compatibility TOC to link the new article under Core .NET libraries.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 3 comments.

File Description
docs/core/compatibility/toc.yml Adds the new breaking change article to the compatibility TOC under .NET 11 Core .NET libraries.
docs/core/compatibility/core-libraries/11/ziparchive-createasync-eager-load.md New article documenting the behavioral change, rationale, and recommended action.
docs/core/compatibility/11.md Adds the new breaking change entry to the .NET 11 index table.

@gewarren
gewarren requested a review from rzikm February 4, 2026 00:26

@rzikm rzikm left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@gewarren
gewarren enabled auto-merge (squash) February 4, 2026 22:09
@gewarren
gewarren merged commit d0aafa9 into main Feb 4, 2026
9 checks passed
@gewarren
gewarren deleted the copilot/fix-ziparchive-createasync-issue branch February 4, 2026 22:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Breaking change]: ZipArchive.CrateAsync eagerly loads all zip archive entries

5 participants