Fix: TextWriterFluidOutput.Dispose() requires force sync (#919) #920
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.
Summary of Changes
This PR adds
IAsyncDisposablesupport toTextWriterFluidOutputand updates all usages to useawait usinginstead ofusingto ensure fully asynchronous disposal.Key changes:
IAsyncDisposableinterface implementation toTextWriterFluidOutputwithDisposeAsync()methodawait usingpattern:FluidRendering.cs(MVC View Engine)FluidViewRenderer.cs(View Engine - bothRenderViewAsyncandRenderPartialAsync)FluidOutputExtensions.cs(3 extension methods)FluidTemplateExtensions.csActionViewResult.cs(Minimal APIs)TextWriterFluidOutputTests.cs- 1073 lines)FluidOutputIntegrationTests.cs- 498 lines)Motivation and Context
Fixes #919
ASP.NET Core disables synchronous I/O by default (
IHttpBodyControlFeature.AllowSynchronousIO = false). The v3.0.0-beta4 release introducedTextWriterFluidOutputwhich used synchronousDispose()that internally calledFlushCore()with synchronous writes. This causedSystem.InvalidOperationException: Synchronous operations are disallowederrors when rendering Liquid templates in ASP.NET Core applications, particularly when response compression (e.g., Brotli) was enabled.How the Changes Were Tested
Added
TextWriterFluidOutputTests.cswith comprehensive unit tests covering:DisposeAsync()behavior and buffer cleanupAdded
FluidOutputIntegrationTests.cswith integration tests covering:Screenshots
N/A - Internal API change, no UI impact.
Checklist
IAsyncDisposableonTextWriterFluidOutputusingstatements toawait usingfor async disposalDispose()still available)#if NETSTANDARD2_0conditional compilation