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

Ali picture Ali · Aug 31, 2018 · Viewed 11.1k times · Source

I am using hangfire in mvc application. I am sending reminder to user for his/her appointment. I have installed hangfire in my app. I have configured hangfire in startup.cs class. But when i run the app, it produce the below error, JobStorage. Current property value has not been initialized. You must set it before using Hangfire Client or Server API.

using Hangfire;
using Hangfire.SqlServer;
using Microsoft.Owin;
using Owin;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using UKC.Data.Infrastructure;
using UKC.UI.Helper;

[assembly: OwinStartup(typeof(UKC.UI.App_Start.Startup))]
namespace UKC.UI.App_Start
{
    public partial class Startup
    {
        public void Configuration(IAppBuilder app)
        {
            ConfigureAuth(app);
            GlobalConfiguration.Configuration
               .UseSqlServerStorage("DbEntities");

            app.UseHangfireDashboard();
            app.UseHangfireServer();

        }
    }
}

Answer

Qamar Zaman picture Qamar Zaman · Apr 16, 2019

For Initializing in Asp.net core

public static void InitializeHangFire()
        {
            var sqlStorage = new SqlServerStorage("connectionString");
            var options = new BackgroundJobServerOptions
            {
                ServerName = "Test Server"
            };
            JobStorage.Current = sqlStorage;
        }