Closed sandromastronardi closed 3 years ago
whoops, it is a double, i checked the issues but because of the name I missed this one: https://github.com/neuecc/Utf8Json/issues/186
it appears to be a .NET Core 3.1 issue
Closed because of being duplicate
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.<>cDisplayClass0_0.<gBind|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: https://github.com/neuecc/Utf8Json/blob/608cf01589cb3feb225a6e51a2324a24466fdaa6/src/Utf8Json.AspNetCoreMvcFormatter/Formatter.cs#L80
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.