MarimerLLC / cslaforum

Discussion forum for CSLA .NET
https://cslanet.com
Other
31 stars 6 forks source link

Synchronous operations are disallowed #856

Closed ghost closed 4 years ago

ghost commented 4 years ago

Hi,

I'm trying to upgrade an existing project from CSLA 4.8.1/ASP.NET Core 2.2 to CSLA 5.1.0-R19110701/ASP.NET Core 3.1 and I'm getting the follwing error when trying to execute a simple Command object that works just fine on 4.8.1:

InternalServerError: Internal Server Error 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)

The exception happens on the command's DataPortal.ExecuteAsync, and DataPortal_Execute never gets called.

Csla.ApplicationContext.DataPortalProxy: Csla.DataPortalClient.HttpProxy, Csla Csla.ApplicationContext.DataPortalUrlString: https://localhost:44350/dataportal

I'm pretty sure I'm doing something wrong on the configuration, but not sure what it is. I've even tried to set AllowSynchronousIO to true but still getting the same error.

public static IHostBuilder CreateHostBuilder(string[] args) =>
            Host.CreateDefaultBuilder(args)
            .ConfigureWebHostDefaults(webBuilder =>
            {
                webBuilder.ConfigureKestrel(serverOptions =>
                {
                    serverOptions.AllowSynchronousIO = true;
                })
                .UseStartup<Startup>();
            });

Added a simple project that shows the error. Again, I suspect my problem is somewhere in the configuration: https://github.com/MarceloJGaray/BugTest51

Thanks

Version and Platform CSLA version: CSLA 5.1.0-R19110701 OS: Windows, Platform: ASP.NET Core

rockfordlhotka commented 4 years ago

This is due to a breaking change in .NET Core 3.x where they now disallow synchronous IO options by default. Unfortunately the serializer used by the data portal does synchronous IO (in memory) and so triggers this issue.

I don't know why your change to Program.cs isn't fixing the issue though, because that is the answer.

Are you sure you are running the web site in Kestrel and not IIS Express? If you are running it in IIS Express then you need a similar configuration entry for IIS.

ghost commented 4 years ago

You are right! I've added the same configuration for IIS and now it works. Thanks!

rockfordlhotka commented 4 years ago

For future reference, here's a ConfigureServices implementation to address the issue.

    public void ConfigureServices(IServiceCollection services)
    {
      // If using Kestrel:
      services.Configure<KestrelServerOptions>(options =>
      {
        options.AllowSynchronousIO = true;
      });

      // If using IIS:
      services.Configure<IISServerOptions>(options =>
      {
        options.AllowSynchronousIO = true;
      });

      services.AddCsla();
    }