Fix XDocument.LoadAsync to not use sync reads#123800
Merged
stephentoub merged 3 commits intodotnet:mainfrom Feb 4, 2026
Merged
Fix XDocument.LoadAsync to not use sync reads#123800stephentoub merged 3 commits intodotnet:mainfrom
stephentoub merged 3 commits intodotnet:mainfrom
Conversation
Contributor
There was a problem hiding this comment.
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.CreateAsyncmethod 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 |
src/libraries/System.Private.Xml.Linq/src/System/Xml/Linq/XDeclaration.cs
Outdated
Show resolved
Hide resolved
Contributor
|
Tagging subscribers to this area: @dotnet/area-system-xml |
stephentoub
approved these changes
Jan 30, 2026
Member
stephentoub
left a comment
There was a problem hiding this comment.
This looks reasonable to me, but @krwq can you take a look, too?
src/libraries/System.Private.Xml.Linq/src/System/Xml/Linq/XDeclaration.cs
Outdated
Show resolved
Hide resolved
This was referenced Jan 30, 2026
Open
…laration.cs Co-authored-by: Stephen Toub <[email protected]>
Member
|
thanks, @lilinus |
lewing
pushed a commit
to lewing/runtime
that referenced
this pull request
Feb 9, 2026
Co-authored-by: Stephen Toub <[email protected]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #100239