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

public void ConfigureServices(IServiceCollection services)
{
    // Add Hangfire services.
    services.AddHangfire(configuration => configuration
      .SetDataCompatibilityLevel(CompatibilityLevel.Version_170)
      .UseSimpleAssemblyNameTypeSerializer()
      .UseRecommendedSerializerSettings()
      .UseSqlServerStorage({my-connection-string},
                           new SqlServerStorageOptions
                           {
                             PrepareSchemaIfNecessary = true,
                             CommandBatchMaxTimeout = TimeSpan.FromMinutes(5),
                             SlidingInvisibilityTimeout = TimeSpan.FromMinutes(5),
                             QueuePollInterval = TimeSpan.Zero,
                             UseRecommendedIsolationLevel = true,
                             UsePageLocksOnDequeue = true,
                             DisableGlobalLocks = true
                           }));
    services.AddHangfireServer();
}

However when I invoke a Hangfire task :

BackgroundJob.Schedule(
    () => CheckUpload({my-data}),
    TimeSpan.FromSeconds({my-interval}));

I receive this error :

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

But I would think this was taken care of by my UseSqlServerStorageOptions init.

1 Like

Had the same issue. It appeared that the supplied connection string was incorrect and I did not have global connection string initialization. In fact, everything you need in the consumer - is installed ā€œHangfireā€ package + setting proper connection string:

private void ConfigureHangfire(IConfiguration configuration)
{
    GlobalConfiguration.Configuration.UseSqlServerStorage(configuration.GetConnectionString("Hangfire"));
}

In my case where I user asp.net mvc5, I needed to restart the application pool in IIS.

Strangeā€¦ In another project I have this error and nothing helps so farā€¦ Iā€™ve also noticed, that Action from AddHangfire is not called prior to calling my appService methodā€¦