Skip to content

HttpResponseStreamWriter WriteLineAsync can cause exception #16740

Closed
@antifree

Description

@antifree

Describe the bug

WriteLineAsync method of HttpResponseStreamWriter in Asp.Net Core 3.0 can cause the following exception:

InvalidOperationException when attempting to write to the response body – with a message “Synchronous operations are disallowed. Call WriteAsync or set AllowSynchronousIO to true instead.”.

I think it occurs, because default implementation on TextWriter creates new Task which calls Write method. This method is overriden in HttpResponseStreamWriter and writes to response stream in synchronous way. I guess it is a bug.

I've found an issue #2895 says this one and other methods should be overriden. But as I see, it is delayed.

Expected behavior

To work without setting AllowSynchronousIO = true or using WriteAsync(line + "\n")

Metadata

Metadata

Assignees

No one assigned

    Labels

    ✔️ Resolution: DuplicateResolved as a duplicate of another issuearea-networkingIncludes servers, yarp, json patch, bedrock, websockets, http client factory, and http abstractionsbugThis issue describes a behavior which is not expected - a bug.

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions