Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

.NET Core 3 preview: Synchronous operations are disallowed

Tags:

I have an Angular.js app that I am porting to .NET Core.

It was working fine in the previous version of .NET Core 3 preview; 3.2.

However, after upgrading to latest 3.3 some of the get requests are returning this error:

InvalidOperationException: Synchronous operations are disallowed. Call WriteAsync or set AllowSynchronousIO to true instead.

I can't see why this is happening with only some requests and not others.

I believe that by default Angular.js does async: xhr.open(method, url, true);

Can anyone shed some light on this?

like image 656
Norbert Norbertson Avatar asked Mar 07 '19 20:03

Norbert Norbertson


2 Answers

This problem is described here: https://github.com/aspnet/AspNetCore/issues/8302

The workaround for now is to manually set AllowSynchronous to true in startup.cs;

// Startup.ConfigureServices

services.Configure<IISServerOptions>(options =>
{
  options.AllowSynchronousIO = true;
});
like image 164
Norbert Norbertson Avatar answered Oct 04 '22 02:10

Norbert Norbertson


It's worth noting that if you host on kestrel directly then your Program.cs should have appropriate ConfigureKestrel call

   public static IWebHostBuilder CreateWebHostBuilder(string[] args) =>
            WebHost.CreateDefaultBuilder(args)
                .UseStartup<Startup>()
                .ConfigureKestrel((context, options) =>
                {
                    options.AllowSynchronousIO = true;
                })
like image 40
pkmiec Avatar answered Oct 04 '22 03:10

pkmiec