[AspNetCore] JobStorage.Current will not be set. Even if it should. Bug/Workaround inside


#1

Hi there,

I have a very simple setup: HangfireServer with HangfireDashboard (.NetCore WebApp) and an Application which acts as a Client (Also .NetCore WebApp). The HangfireServer runs perfectly, no problems there. The Client on the other side crashes with the reason “JobStorage.Current property not Set”. Well, it should be set actually.

Client Startup.cs Class (partially):

public void ConfigureServices(IServiceCollection services)
{
	...
	services.AddHangfire(x => x.UseSqlServerStorage("xyz"));
	...
}

According to my research in the source code of the “AddHangfire” extension, it should (lazy) initialize the JobStorage, which is clearly set to be a SqlStorage.

My Workaround:

Adding this to the Client Startup.cs:

public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory, IServiceProvider sp)
{
	...
	sp.GetRequiredService<JobStorage>();
	...
}

To force it to resolve the JobStorage before the first request goes to the BackgroundJob class.

Looks a bit like a bug to me.

Any thoughts?

Best regards,
Stefan