You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Describe the issue
.net 8 Azure Function in program.cs when configuring .ConfigureFunctionsWebApplication(worker => worker.UseNewtonSoftJson()) I will get a an error "Synchronous operations are disallowed. Call WriteAsync or set AllowSynchronousIO to true instead"
public async Task<HttpResponseData> Get([HttpTrigger(AuthorizationLevel.Function, "get", Route = "v1/user")] HttpRequestData req)
{
...
var response = req.CreateResponse(HttpStatusCode.OK);
await response.WriteAsJsonAsync(user);
return response;
}
It will bomb out on .WriteAsJsonAsync() from swagger and postman. It could be my object I am returning but..
My work around:
My work around was to remove worker => worker.UseNewtonSoftJson() from my config.
var host = new HostBuilder()
.ConfigureFunctionsWebApplication() //Note: OpenApi says to configure this as worker => worker.UseNewtonSoftJson(). This will cause a Synchronous operations are disallowed. Call WriteAsync or set AllowSynchronousIO to true instead. I removed it and things seem to work?
.ConfigureServices((hostContext, services) =>
...
This works for swagger and json. It could be the object I am serializing that doesn't play nice with NewtonSoft. idk. The link make it seem like there's some other issue with flushing on write.¯_(ツ)_/¯.
The text was updated successfully, but these errors were encountered:
Same here. Instead I use WriteAsync and Stream. Works...
//await response.WriteAsJsonAsync(responseDTO); <-- dont workvarserialized=JsonConvert.SerializeObject(responseDTO);varms=newMemoryStream(Encoding.UTF8.GetBytes(serialized));awaitresponse.Body.WriteAsync(ms.ToArray());
Describe the issue
.net 8 Azure Function in program.cs when configuring .ConfigureFunctionsWebApplication(worker => worker.UseNewtonSoftJson()) I will get a an error "Synchronous operations are disallowed. Call WriteAsync or set AllowSynchronousIO to true instead"
That led me to this link.
The code:
}
It will bomb out on .WriteAsJsonAsync() from swagger and postman. It could be my object I am returning but..
My work around:
My work around was to remove worker => worker.UseNewtonSoftJson() from my config.
This works for swagger and json. It could be the object I am serializing that doesn't play nice with NewtonSoft. idk. The link make it seem like there's some other issue with flushing on write.¯_(ツ)_/¯.
The text was updated successfully, but these errors were encountered: