guryanovev / CrystalQuartz

pluggable UI for Quartz.NET
MIT License
1.01k stars 313 forks source link

Synchronous operations are disallowed with .Net 6. Is the workaround still the same? #96

Open s3YwCf2ZbfJG4SHAfjQMAjtsf opened 2 years ago

s3YwCf2ZbfJG4SHAfjQMAjtsf commented 2 years ago

Is this workaround still the solution for the error below?

    builder.Services.Configure<IISServerOptions>(options =>
    {
         options.AllowSynchronousIO = true;
    );
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 System.IO.Stream.Write(ReadOnlySpan`1 buffer)
   at Microsoft.AspNetCore.Watch.BrowserRefresh.WebSocketScriptInjection.TryInjectLiveReloadScript(Stream baseStream, ReadOnlySpan`1 buffer)
   at Microsoft.AspNetCore.Watch.BrowserRefresh.ResponseStreamWrapper.Write(Byte[] buffer, Int32 offset, Int32 count)
   at CrystalQuartz.WebFramework.Request.AbstractFileRequestHandler.<>c__DisplayClass4_0.<WriteResourceToStream>b__0(Stream outputStream)
   at CrystalQuartz.AspNetCore.CrystalQuartzPanelMiddleware.Invoke(HttpContext httpContext)
   at Microsoft.AspNetCore.Builder.Extensions.MapMiddleware.InvokeCore(HttpContext context, PathString matchedPath, PathString remainingPath)
   at Microsoft.AspNetCore.Session.SessionMiddleware.Invoke(HttpContext context)
   at Microsoft.AspNetCore.Session.SessionMiddleware.Invoke(HttpContext context)
   at Microsoft.AspNetCore.Authorization.AuthorizationMiddleware.Invoke(HttpContext context)
   at Swashbuckle.AspNetCore.SwaggerUI.SwaggerUIMiddleware.Invoke(HttpContext httpContext)
   at Swashbuckle.AspNetCore.Swagger.SwaggerMiddleware.Invoke(HttpContext httpContext, ISwaggerProvider swaggerProvider)
   at Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddleware.Invoke(HttpContext context)
oscar230 commented 1 year ago

How would I use this with some server other than IISServerOptions @s3YwCf2ZbfJG4SHAfjQMAjtsf ?

s3YwCf2ZbfJG4SHAfjQMAjtsf commented 1 year ago

Unfortunately, I only know IIS. What are you using instead of IIS?

I am hoping that Crystal Quartz will get upgraded.

Unfortunately, I think this project might be on hold or "dead".

oscar230 commented 1 year ago

Unfortunately, I only know IIS. What are you using instead of IIS?

I am using Kestrel, it is the default in ASP.NET Core 6.

I am hoping that Crystal Quartz will get upgraded.

I'm hoping that as well.

Unfortunately, I think this project might be on hold or "dead".

It would be great to draw some attention to it, I think this would be useful for me with my customers, hopefully I can contribute some time into upgrading this to ASP.NET Core 6. It is the latest LTS so I believe it should be prioritized instead of version 7.

// Oscar

s3YwCf2ZbfJG4SHAfjQMAjtsf commented 1 year ago

There are 3 pull requests pending, so I am not sure spending the time without forking to a new Github will help.

https://stackoverflow.com/questions/47735133/asp-net-core-synchronous-operations-are-disallowed-call-writeasync-or-set-all

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;
    });
}
oscar230 commented 1 year ago

There are 3 pull requests pending, so I am not sure spending the time without forking to a new Github will help.

https://stackoverflow.com/questions/47735133/asp-net-core-synchronous-operations-are-disallowed-call-writeasync-or-set-all

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;
    });
}

Hi thanks for the reply, I will try that out when I find the time. And yes, sadly maybe this project is dead.

grcodemonkey commented 1 year ago

I was able to use a middleware call to may this change only for that CrystalQuartz endpoints

    public static void ApplyWorkaroundForAllowSynchronousIO(IApplicationBuilder app) =>
        app.Use(
            async (context, next) =>
            {
                if (context.Request.Path.StartsWithSegments("/quartz")) {
                    var feature = context.Features.Get<IHttpBodyControlFeature>();
                    if (feature != null) {
                        feature.AllowSynchronousIO = true;
                    }
                }

                await next();
            }
        );
oscar230 commented 1 year ago

I was able to use a middleware call to may this change only for that CrystalQuartz endpoints

    public static void ApplyWorkaroundForAllowSynchronousIO(IApplicationBuilder app) =>
        app.Use(
            async (context, next) =>
            {
                if (context.Request.Path.StartsWithSegments("/quartz")) {
                    var feature = context.Features.Get<IHttpBodyControlFeature>();
                    if (feature != null) {
                        feature.AllowSynchronousIO = true;
                    }
                }

                await next();
            }
        );

Awesome, thanks! 😄