Search code examples
hangfire

Issue when configuring Hangfire in ASP.NET app


I'm attempting to wire up Hangfire in my ASP.NET application (not Core) using the Global.asax.cs route explained in their documentation. However, none of their extensions methods on GlobalConfiguration.Configuration seem to be working for me. It appears, for one example, that SetDataCompatibiltyLevel() method extends Hangfire.IGlobalConfiguration, which my GlobalConfiguration.Configuration does not inherit from. I even backed off a few versions of Hangfire and it doesn't seem to make a difference. When I attempt to access the extensions method directly, I get this: enter image description here


Solution

  • Prefix GlobalConfiguration class with the Hangfire namespace – System.Web.Http namespace defines its own GlobalConfiguration class, so you get a conflict. And that another class is referenced, most likely because you have the System.Web.Http namespace included in the beginning of the file.

    Hangfire.GlobalConfiguration.Configuration
        .SetDataCompatibilityLevel(CompatibiltyLevel.Version_170);
    

    You can also combine all the calls to the GlobalConfiguration class in a single chain:

    Hangfire.GlobalConfiguration.Configuration
        .SetDataCompatibilityLevel(CompatibiltyLevel.Version_170)
        .UseXXX()
        .UseYYYStorage();