aspnetcore: StaticHtmlRenderer uses synchronous writes which eventually fails
All the prerendering logic inside StaticHtmlRenderer (and wrapper logic in EndpointHtmlRenderer’s WriteComponentHtml) performs synchronous writes against a TextWriter that wraps the output stream.
This works up to a point, but once you write too much content (presumably exceeding the writer’s internal buffer), the system will throw InvalidOperationException: Synchronous operations are disallowed. Call WriteAsync or set AllowSynchronousIO to true instead.. This can happen with or without streaming SSR.
Likely solutions:
- We may be able to change the prerendering logic to use asynchronous writes throughout
- Or we may need to write the prerendering output to a buffer and then asynchronously flush that to the response writer at the end of each batch
About this issue
- Original URL
- State: closed
- Created a year ago
- Reactions: 9
- Comments: 15 (9 by maintainers)
@ricardok1 You can get a nightly build containing this fix right now if you want from https://github.com/dotnet/installer/blob/main/README.md#installers-and-binaries. That’s my recommendation on how to avoid the problem until RC1 is out.
I am still getting this error on preview 7
@SimenArntsen Yes, it’s partially fixed in RC1 (works if not streaming rendering) and will be fully fixed in RC2.