Upgrading ASP.NET project from .NET Core 3.1 to .NET 6.0 makes Hangfire crash the app at startup

Changing target framework from .NET Core 3.1 to .NET 6.0 makes the ASP.NET app crash when services.AddHangfireServer() is called. It’s happening on local development machines only (same result on both Linux & Windows dev boxes), but oddly enough, works on production servers (IIS).

Here is the output when run with IISEXPRESS:

The program ‘[8532] iisexpress.exe: Program Trace’ has exited with code 0 (0x0).
The program ‘[8532] iisexpress.exe’ has exited with code 3221225477 (0xc0000005) ‘Access violation’.
The program ‘’ has exited with code 4294967295 (0xffffffff).
The program ‘’ has exited with code 4294967295 (0xffffffff).

Here is the output when run with kestrel:

warn: Microsoft.AspNetCore.Server.Kestrel[0]
Overriding address(es) ‘https://localhost:5001, http://localhost:5000’. Binding to endpoints defined via IConfiguration and/or UseKestrel() instead.
info: Microsoft.Hosting.Lifetime[14]
Now listening on: http://[::]:5003
info: Microsoft.Hosting.Lifetime[0]
Application started. Press Ctrl+C to shut down.
info: Microsoft.Hosting.Lifetime[0]
Hosting environment: Development
info: Microsoft.Hosting.Lifetime[0]
Content root path: C:\Code\project\someproject.Dashboard
Stack overflow.

Has anyone encountered the problem before and know how to safely upgrade the projects to .NET 6.0 ?

Thanks in advance.

When you upgraded the .net version, did you also reinstall your packages? That would be step one. Beyond that… I did not run into any issues that I can recall, but I also went from 3.1 to 5 and then to 6, so perhaps I’ve forgotten any issues I ran into in the first upgrade.

Do you have recurring jobs and did you get rid of startup.cs when upgrading? If you did, you have to rewrite how you instantiate the recurring jobs.

FROM: RecurringJob.AddOrUpdate<>();

TO: app.Services.GetService().AddOrUpdate<>();

@Tieson_Trowbridge yes, we did follow the recommended path.
@khan no recurring jobs involved in that particular project.

We’ll try to rebuild the API from scratch and let you know

Curious as to whether you figured this out? Trying to think of what could cause a StackOverflowException within Hangfire.

Does it happen only when enabling the dashboard (so, crashes on startup)? Or when trying to access the dashboard?

There would also be schema updates that Hangfire wants to run, on startup - I’d assume your local machines are running under different users than the production server(s), so it’s possible that the app is crashing when attempting to run the migrations?

@Tieson_Trowbridge commenting this:

        app.UseHangfireDashboard("/monitor", new DashboardOptions
        {
            Authorization = new[] { new OpenToAllAuthorizationFilter() }
        });

Made the API to start properly using .NET 6.0 as the target framework. However, we use Redis with Pro extension. No SQL Server Migration involved.

What do you think?

Just so I follow, you’re saying that if you comment out the above lines (which means the dashboard isn’t enabled) allows the application to start up normally?

Does it work if you remove the authorization filter?

Yes if I comment it, I get the 401 error but IISEXPRESS is not crashing.