https://github.com/aspnet/AspNetCore/issues/7644#issuecomment-470690541
System.InvalidOperationException: Synchronous operations are disallowed. Call WriteAsync or set AllowSynchronousIO to true instead.

at Microsoft.AspNetCore.Server.IIS.Core.HttpResponseStream.Write(Byte[] buffer, Int32 offset, Int32 count)

at Microsoft.AspNetCore.Server.IIS.Core.WrappingStream.Write(Byte[] buffer, Int32 offset, Int32 count)

at Microsoft.AspNetCore.WebUtilities.HttpResponseStreamWriter.FlushInternal(Boolean flushEncoder)

at Microsoft.AspNetCore.WebUtilities.HttpResponseStreamWriter.Write(String value)

at Newtonsoft.Json.JsonTextWriter.WriteValue(Guid value)

at Newtonsoft.Json.JsonWriter.WriteValue(Nullable`1 value)

at Newtonsoft.Json.JsonWriter.WriteValue(JsonWriter writer, PrimitiveTypeCode typeCode, Object value)

at Newtonsoft.Json.Serialization.JsonSerializerInternalWriter.SerializeObject(JsonWriter writer, Object value, JsonObjectContract contract, JsonProperty member, JsonContainerContract collectionContract, JsonProperty containerProperty)

at Newtonsoft.Json.Serialization.JsonSerializerInternalWriter.SerializeList(JsonWriter writer, IEnumerable values, JsonArrayContract contract, JsonProperty member, JsonContainerContract collectionContract, JsonProperty containerProperty)

at Newtonsoft.Json.Serialization.JsonSerializerInternalWriter.Serialize(JsonWriter jsonWriter, Object value, Type objectType)

at Newtonsoft.Json.JsonSerializer.SerializeInternal(JsonWriter jsonWriter, Object value, Type objectType)

at Newtonsoft.Json.JsonSerializer.Serialize(JsonWriter jsonWriter, Object value)

at Microsoft.AspNetCore.Mvc.Formatters.NewtonsoftJsonOutputFormatter.WriteResponseBodyAsync(OutputFormatterWriteContext context, Encoding selectedEncoding)

at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.InvokeResultAsync(IActionResult result)

at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.InvokeNextResultFilterAsync[TFilter,TFilterAsync]()

at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.Rethrow(ResultExecutedContext context)

at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.ResultNext[TFilter,TFilterAsync](State& next, Scope& scope, Object& state, Boolean& isCompleted)

at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.InvokeResultFilters()
 at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.InvokeNextResourceFilter()

at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.Rethrow(ResourceExecutedContext context)

at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.Next(State& next, Scope& scope, Object& state, Boolean& isCompleted)

at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.InvokeFilterPipelineAsync()

at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.InvokeAsync()

at Microsoft.AspNetCore.Authentication.AuthenticationMiddleware.Invoke(HttpContext context)

at Microsoft.AspNetCore.Routing.EndpointRoutingMiddleware.Invoke(HttpContext httpContext)
 at Microsoft.AspNetCore.StaticFiles.StaticFileMiddleware.Invoke(HttpContext context)

at Microsoft.AspNetCore.Diagnostics.EntityFrameworkCore.MigrationsEndPointMiddleware.Invoke(HttpContext context)

at Microsoft.AspNetCore.Diagnostics.EntityFrameworkCore.DatabaseErrorPageMiddleware.Invoke(HttpContext httpContext)

at Microsoft.AspNetCore.Diagnostics.EntityFrameworkCore.DatabaseErrorPageMiddleware.Invoke(HttpContext httpContext)

at Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddleware.Invoke(HttpContext context)
Thanks, would it be helpful to share my startup.cs?
In the AsyncIO PR I added temporary overrides for XML and razor, but Json didn't get one for some reason. The tests passed without it, likely because they never wrote large enough data to fill the buffer and trigger a sync flush.
@GusBeare how large is the object you're serializing? Does this repro with small responses?
Workarounds are already outlined in https://github.com/aspnet/AspNetCore/issues/7644.
Not huge, about 600 rows.
Not small. Those buffers are only KB. Go ahead and apply the workaround. We'll get this fixed for the next preview. @mkArtakMSFT
Many thanks. I'll try the workarounds tomorrow: getting late here. Had enough.
Though it would be helpful if you could point me in the right direction as to how to do this globally.
There are lots of failing requests.
"Each server has a AllowSynchronousIO option that controls this behavior and the default for all of them is now false."
I can't find anything on how to set it for IIS in process.
I am still baffled as to why it's failing though because these are async requests from angularjs.
The JSON serializer is synchronously writing to the response body.
For IIS In-proc it should be something like this.
https://docs.microsoft.com/en-us/aspnet/core/host-and-deploy/iis/?view=aspnetcore-2.2#iis-options
// Startup.ConfigureServices
services.Configure<IISServerOptions>(options =>
{
options.AllowSynchronousIO = true;
});
I have this same issue using Kestrel .net core 3. Even with the following code implemented:
services.Configure<IISServerOptions>(options =>
{
options.AllowSynchronousIO = true;
});
Is there a Kestrel part to this workaround? I am not using IIS, just Kestrel.
Our solution was to replace GetJsonAsync with straight GetAsync and deserialise the stringcontent for the time being while the issue is sorted out - this has no issues with the record load.
@aford22 what was the line before that? The complete sample for Kestrel should be:
services.Configure<KestrelServerOptions>(options =>
{
options.AllowSynchronousIO = true;
});
Bingo, @Tratcher ! That worked perfectly.
Thank you.
I know this is closed, but I just discovered why I was suffering from this issue on very small requests (100 bytes). I had a circular reference between a two classes in EF Core, which began generating a larger response and triggering this issue. Although setting AllowSynchronousIO = true in the method, for me, did not resolve the issue.
I still have this error in preview 5, I'm not sure how it got here. The above mentioned workaround worked for me though.
I thought it was worth mentioning since it was supposed to be fixed in preview 4.
@kevinsnijder this PR was only a temporary fix. https://github.com/aspnet/AspNetCore/issues/6397 replaced it and was part of preview5. If you're having a similar problem with preview5 please open a new issue and tell @pranavkm.
@Tratcher I looked at some of the referenced issues and I was unable to determine if Json.net will still throw if I turn this on in preview 8. I'm assuming so as it does sync operations (unless there was a pr that I'm not seeing).
@pranavkm ?
@pranavkm were you able to determine if this is still an issue?
@niemyjski could you please file a separate issue with a clear description of what you're seeing?
Most helpful comment
The JSON serializer is synchronously writing to the response body.
For IIS In-proc it should be something like this.
https://docs.microsoft.com/en-us/aspnet/core/host-and-deploy/iis/?view=aspnetcore-2.2#iis-options
// Startup.ConfigureServices