This repository was archived by the owner on Dec 14, 2018. It is now read-only.
This repository was archived by the owner on Dec 14, 2018. It is now read-only.
Cannot write to Response.Body in 1.1 #5555
Closed
Description
I've just updated an app to version 1.1 and some code that was working started throwing exception saying
System.InvalidOperationException: OnStarting cannot be set, response has already started.
at Microsoft.AspNetCore.Server.Kestrel.Internal.Http.Frame.OnStarting(Func`2 callback, Object state)
at Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.Next(State& next, Scope& scope, Object& state, Boolean& isCompleted)
at Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.<InvokeNextResourceFilter>d__22.MoveNext()
It turns out that the issue was down to writing to Response.Body in my MVC actions. I've worked around this by downloading to a byte array and then returning File(array, contentType).
However I could not easily find any reason behind this - is this an error, desired functionality or just something wrong I'm doing?