Open stianl opened 2 years ago
Tagging subscribers to this area: @dotnet/area-system-xml See info in area-owners.md if you want to be subscribed.
Author: | stianl |
---|---|
Assignees: | - |
Labels: | `area-System.Xml`, `untriaged` |
Milestone: | - |
I think changing the XSL compiler to work async would be a bit of work and not just a simple fix. The exception is coming from the stream. Perhaps an acceptable workaround would be to use MemoryStream when creating XmlWriter and then copy content from MemoryStream to the response body using async method, something like:
using var ms = new MemoryStream();
await using var writer = XmlWriter.Create(ms, new XmlWriterSettings { Async = true });
ms.Position = 0;
await ms.CopyToAsync(Response.Body);
Description
It's not possible to write to
Response.Body
stream usingXslCompiledTransform
. Since synchronous writes are not allowed, I've setAsync = true
on theXmlWriter
used withXslCompiledTransform
, but this fails as well.Using an XmlWriter directly and async write/flush methods works fine so I suspect the problem lies with
XslCompiledTransform
.Reproduction Steps
Can be reproduced with this method:
Without setting
Async = true
in XmlWriterSettings the following (expected) exception is thrown:Expected behavior
No exception
Actual behavior
Application throws exception:
Regression?
No response
Known Workarounds
No response
Configuration
.NET 6, tested on macOS (M1) and Windows (x64).
Other information
May be related to #31104.