AspNetCoreMvcFormatter uses syncrhonous deserialisations
sandromastronardi opened this issue · 2 comments
I have an app that throws this error:
System.InvalidOperationException: Synchronous operations are disallowed. Call ReadAsync or set AllowSynchronousIO to true instead.
at Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http.HttpRequestStream.Read(Byte[] buffer, Int32 offset, Int32 count)
at Utf8Json.JsonSerializer.FillFromStream(Stream input, Byte[]& buffer)
at Utf8Json.JsonSerializer.Deserialize[T](Stream stream, IJsonFormatterResolver resolver)
at Deserialize(Stream , IJsonFormatterResolver )
at Utf8Json.JsonSerializer.NonGeneric.Deserialize(Type type, Stream stream, IJsonFormatterResolver resolver)
at Utf8Json.AspNetCoreMvcFormatter.JsonInputFormatter.ReadAsync(InputFormatterContext context)
at Microsoft.AspNetCore.Mvc.ModelBinding.Binders.BodyModelBinder.BindModelAsync(ModelBindingContext bindingContext)
at Microsoft.AspNetCore.Mvc.ModelBinding.ParameterBinder.BindModelAsync(ActionContext actionContext, IModelBinder modelBinder, IValueProvider valueProvider, ParameterDescriptor parameter, ModelMetadata metadata, Object value)
at Microsoft.AspNetCore.Mvc.Controllers.ControllerBinderDelegateProvider.<>c__DisplayClass0_0.<g__Bind|0>d.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.g__Awaited|13_0(ControllerActionInvoker invoker, Task lastTask, State next, Scope scope, Object state, Boolean isCompleted)
at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.g__Awaited|19_0(ResourceInvoker invoker, Task lastTask, State next, Scope scope, Object state, Boolean isCompleted)
at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.g__Logged|17_1(ResourceInvoker invoker)
at Microsoft.AspNetCore.Routing.EndpointMiddleware.g__AwaitRequestTask|6_0(Endpoint endpoint, Task requestTask, ILogger logger)
at Microsoft.AspNetCore.Authorization.AuthorizationMiddleware.Invoke(HttpContext context)
at Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddleware.Invoke(HttpContext context)
I don't know if it is because my web app runs in a windows service but it appears to start here:
Here a Read is called instead of a ReadAsync.... the resolution to make everything synchronous (as suggested In the error) is not the right way to go ofcourse.
whoops, it is a double, i checked the issues but because of the name I missed this one:
#186
it appears to be a .NET Core 3.1 issue
Closed because of being duplicate