Skip to content

Conversation

@lilinus
Copy link
Contributor

@lilinus lilinus commented Jan 30, 2026

Fixes #100239

Copilot AI review requested due to automatic review settings January 30, 2026 14:41
@dotnet-policy-service dotnet-policy-service bot added the community-contribution Indicates that the PR has been added by a community member label Jan 30, 2026
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This pull request fixes an issue where XDocument.LoadAsync was incorrectly using synchronous reads when processing XML declarations, violating the async contract. The fix ensures that the async code path uses await r.ReadAsync() instead of the synchronous r.Read().

Changes:

  • Moved XML declaration handling from shared initialization code into separate sync/async code paths
  • Added new XDeclaration.CreateAsync method to handle XML declaration creation asynchronously
  • Added comprehensive tests to verify that async methods only call async I/O operations and sync methods only call sync I/O operations

Reviewed changes

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

File Description
src/libraries/System.Private.Xml.Linq/src/System/Xml/Linq/XDocument.cs Moved XML declaration handling from InitLoad into Load and LoadAsyncInternal to support separate sync/async code paths
src/libraries/System.Private.Xml.Linq/src/System/Xml/Linq/XDeclaration.cs Added CreateAsync method to support asynchronous XML declaration creation
src/libraries/System.Private.Xml.Linq/tests/misc/LoadSaveAsyncTests.cs Added test coverage to verify sync/async I/O patterns are correctly followed

{
string? version = r.GetAttribute("version");
string? encoding = r.GetAttribute("encoding");
string? standalone = r.GetAttribute("standalone");
Copy link

Copilot AI Jan 30, 2026

Choose a reason for hiding this comment

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

Extra whitespace before 'standalone' variable name. Should be single space like the lines above.

Copilot uses AI. Check for mistakes.
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
string? standalone = r.GetAttribute("standalone");
string? standalone = r.GetAttribute("standalone");

@dotnet-policy-service
Copy link
Contributor

Tagging subscribers to this area: @dotnet/area-system-xml
See info in area-owners.md if you want to be subscribed.

Copy link
Member

@stephentoub stephentoub left a comment

Choose a reason for hiding this comment

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

This looks reasonable to me, but @krwq can you take a look, too?

{
string? version = r.GetAttribute("version");
string? encoding = r.GetAttribute("encoding");
string? standalone = r.GetAttribute("standalone");
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
string? standalone = r.GetAttribute("standalone");
string? standalone = r.GetAttribute("standalone");

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area-System.Xml community-contribution Indicates that the PR has been added by a community member

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Synchronous call inside XDocument.LoadAsync

2 participants