我们的API工作正常,最近我们从ServiceStack 4.5.14更改为ServiceStack.Core 1.0.44以使用功能强大的Kestrel http服务器。
框架抛出异常并被AppHost.UncaughtExceptionHandlers
System.InvalidOperationException: StatusCode cannot be set because the response has already started.
at Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http.Frame.ThrowResponseAlreadyStartedException(String value)
at Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http.Frame.set_StatusCode(Int32 value)
at ServiceStack.HttpExtensions.EndRequestWithNoContent(IResponse httpRes)
at ServiceStack.HttpResponseExtensionsInternal.WriteToResponse(IResponse httpRes, IRequest httpReq, Object result, Byte[] bodyPrefix, Byte[] bodySuffix, CancellationToken token)
at ServiceStack.Host.RestHandler.<>c__DisplayClass13_1.<ProcessRequestAsync>b__1(Object response)
at ServiceStack.AsyncExtensions.<>c__DisplayClass1_0`1.<ContinueClosure>b__0(Task innerTask)
UPDATE :升级到ServiceStack.Core v5.0.2后,仍然会出现。然而,堆栈跟踪是不同的。
System.InvalidOperationException: StatusCode cannot be set because the response has already started.
at Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http.Frame.ThrowResponseAlreadyStartedException(String value)
at Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http.Frame.set_StatusCode(Int32 value)
at ServiceStack.HttpExtensions.EndRequestWithNoContent(IResponse httpRes)
at ServiceStack.HttpResponseExtensionsInternal.WriteToResponse(IResponse httpRes, IRequest httpReq, Object result, Byte[] bodyPrefix, Byte[] bodySuffix, CancellationToken token)
at ServiceStack.Host.Handlers.ServiceStackHandlerBase.<HandleResponseNext>d__13.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at ServiceStack.Host.Handlers.ServiceStackHandlerBase.<HandleResponse>d__12.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at ServiceStack.Host.RestHandler.<ProcessRequestAsync>d__14.MoveNext()