Hangfire: JobStorage.Current property value error

Created on 24 Apr 2017  路  1Comment  路  Source: HangfireIO/Hangfire

Everything was working ok until I move to different dev machine. I'm getting the following error:

System.InvalidOperationException: 'JobStorage.Current property value has not been 
initialized. You must set it before using Hangfire Client or Server API.'

I have my mongo running, and I didn't change anything. This is how I add things,

services.AddHangfire(x => x.UseMongoStorage(conString, databaseName);

services.AddScoped<IBackgroundJobClient, BackgroundJobClient>();

I inject IBackgroundJobClient , and do

_client.Enqueue(() => MethodEnqueued(...));

What puzzles me is that I didn't change anything, and everything was working fine few hours ago.

Hangfire.AspNetCore v1.6.12, Hangfire.Mongo v0.3.2
question

Most helpful comment

Remove the following line:

services.AddScoped<IBackgroundJobClient, BackgroundJobClient>();

The AddHangfire() method already registers a correct IBackgroundJobClient implementation, so you don't need to. With that line, you override it with a default-constructed BackgroundJobClient (which uses static property JobStorage.Current instead of resolving it from service container), so you get the error.

>All comments

Remove the following line:

services.AddScoped<IBackgroundJobClient, BackgroundJobClient>();

The AddHangfire() method already registers a correct IBackgroundJobClient implementation, so you don't need to. With that line, you override it with a default-constructed BackgroundJobClient (which uses static property JobStorage.Current instead of resolving it from service container), so you get the error.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

dgaspar picture dgaspar  路  4Comments

odinserj picture odinserj  路  4Comments

abdelrady picture abdelrady  路  4Comments

cottsak picture cottsak  路  3Comments

nsnail picture nsnail  路  3Comments