Repository navigation
Exception thrown when streaming certain XML values via XmlReader #4756
Description
Activity
🔍 Triage Summary
Check Result Issue type Bug Environment All required environment details provided for investigation Area No exact match in the standard area label list (this affects XML value streaming via SqlDataReader.GetXmlReader/SqlStreamencoding detection, not pooling/AKV/JSON/SNI/bulk copy/vector/async); closest general fit would beArea\Netcore, though the root cause is in shared encoding-detection logic likely affecting both netfx and netcore code pathsDuplicates None found (exact match); related but distinct: #1877 (O(N^2) perf reading XML with SequentialAccess), #1903 (NullReferenceException streaming XML async, closed), #3035 (ARM test flakiness in XmlReader test) Regression Not indicated — no prior-working-version boundary mentioned Analysis
This bug affects
SqlDataReader.GetXmlReader()when streaming anxmlvalue underCommandBehavior.SequentialAccess. SQL Server streamsxmlvalues as BOM-less UTF-16LE, but some code paths that construct the resultingXmlReader(unlike others that wrap with a BOM-synthesizingSqlStream) don't specify an explicit encoding, so .NET's XML encoding-detection logic can misidentify BOM-less UTF-16LE content as UTF-8 whenever the first character isn't<. This produces a corrupted read and anXmlExceptionon the very firstRead()call. The report includes a clear, minimal repro, full stack trace, and complete environment details. Severity: P2 (correctness bug with a clear, narrow root cause and workaround already identified, but no data loss/security impact and a fix is already proposed).Next Steps
- A fix is already proposed in Fix exception thrown when streaming certain XML values via XmlReader #4757 (same author), which sets the
XmlReaderencoding explicitly toEncoding.Unicodeto bypass the faulty detection logic, and updatesDataStreamTestmanual tests (GetFieldValueAsync_OfXmlReader,GetFieldValue_OfXmlReader,GetXmlReader) to cover the pathological case. Maintainers should prioritize reviewing/merging Fix exception thrown when streaming certain XML values via XmlReader #4757 rather than assigning this to Copilot coding agent for independent investigation, since the fix and tests are already in hand. - Recommend reviewing O(N^2) performance when reading XML with SequentialAccess #1877 and NullReferenceException when streaming XML asynchronously from DB #1903 for context, as they involve related (but not identical) XML-over-
SequentialAccessstreaming pitfalls in the same code area; worth confirming Fix exception thrown when streaming certain XML values via XmlReader #4757 doesn't regress those scenarios. - Once Fix exception thrown when streaming certain XML values via XmlReader #4757 merges, this issue should auto-close via the "Closes Exception thrown when streaming certain XML values via XmlReader #4756" reference.
Note: This triage summary is auto-generated by an AI agent. The analysis and suggestions above have not been verified by a human maintainer. Please treat as preliminary guidance only.
Generated by SqlClient Issue Auto-Triage for #4756 · copilot · auto · 35.8 AIC · ⌖ 12.7 AIC · ⊞ 11.8K · ◷
- A fix is already proposed in Fix exception thrown when streaming certain XML values via XmlReader #4757 (same author), which sets the
Suggested label: Repro Available ✔️
- addedRepro Available ✔️Issues that are reproducible with repro provided.Issues that are reproducible with repro provided.
on Oct 1, 2026
Metadata
Metadata
Assignees
Labels
Type
Projects
- StatusShow more project fieldsDone
Describe the bug
When streaming with
CommandBehavior.SequentialAccess, if anxmlvalue is a fragment beginning with any character other than<, thenSqlDataReader.GetXmlReader(…)returns a reader doomed to throw an exception.This issue is fixed by #4757.
To reproduce
Expected behavior
Program exits cleanly.
Further technical details
Microsoft.Data.SqlClient version: 7.1.0
.NET target: .NET 10.0
SQL Server version: SQL Server 2025
Operating system: Windows 11 25H2