Closed ChaosEngine closed 6 years ago
That workaround is suspect as it does exactly the same thing that response.WriteAsync does internally. https://github.com/aspnet/HttpAbstractions/blob/87cd79d6fc54bb4abf07c1e380cd7a9498a78612/src/Microsoft.AspNetCore.Http.Abstractions/Extensions/HttpResponseWritingExtensions.cs#L63-L64
@Tratcher O gosh, of course your right. It was meant to be:
var bytes = Encoding.UTF8.GetBytes(some_html.ToString());
response.Body.Write(bytes, 0, bytes.Length);
as a working fix-up (non-async version).
https://github.com/ChaosEngine/SomeMiddleware/blob/49af9462989ff19794e0956fa15aac92e422da7d/WebApplication1/SomeMiddleware.cs#L37
async void RespondWithIndexHtml
must be async Task RespondWithIndexHtml
and it must be await'd when called in Invoke. Otherwise it runs on a background thread after the response completes.
Ha, naturally :-) Thank you for pointing this out; hopefully will make a PR for https://github.com/domaindrivendev/Swashbuckle.AspNetCore/issues/600. Closing this issue now.
Title
Unhandled Exception: System.InvalidOperationException: Can not access a closed Stream. happens when executing
on net461 target framework, netcoreapp2.0 proves to work fine
Functional impact
IIS Express and kestrel crashes (process exists) when running simple middleware app on net461. Does not happen on netcoreapp2.0
Minimal repro steps
Sample project exposing the bug: https://github.com/ChaosEngine/SomeMiddleware/releases/tag/bug1.0 line affecting the bug: https://github.com/ChaosEngine/SomeMiddleware/blob/49af9462989ff19794e0956fa15aac92e422da7d/WebApplication1/SomeMiddleware.cs#L58
Expected result
As with netcoreapp2.0 the page result should be returned from the middleware and gzip compression should be enabled.
Actual result
The IIS Express or dotnet process crashes with error message:
Further technical details
the bug could be worked around by using different use of following:
Original bug was discovered in Swashbuckle.AspNetCore on newer version than 1.1.0 and reported as https://github.com/domaindrivendev/Swashbuckle.AspNetCore/issues/600.