HangfireIO/Hangfire · error · ArgumentNullException

app

Error message

app

What it means

Thrown as ArgumentNullException by the obsolete OwinBootstrapper.UseHangfire extension when the 'app' IAppBuilder argument is null. The bootstrapper wires storage, activator, filters, servers, and the dashboard onto the OWIN pipeline; a null app builder means there is no pipeline to extend, so it fails fast at line 40. The whole class is [Obsolete] in favor of GlobalConfiguration plus UseHangfireDashboard/UseHangfireServer.

Source

Thrown at src/Hangfire.Core/Obsolete/OwinBootstrapper.cs:40

namespace Hangfire
{
    /// <exclude />
    [Obsolete("Please use `GlobalConfiguration` class for configuration, or `IAppBuilder.UseHangfireDashboard` and `IAppBuilder.UseHangfireServer` OWIN extension methods instead. Will be removed in version 2.0.0.")]
    public static class OwinBootstrapper
    {
        /// <summary>
        /// Bootstraps Hangfire components using the given configuration
        /// action and maps Hangfire Dashboard to the app builder pipeline
        /// at the configured path ('/hangfire' by default).
        /// </summary>
        /// <param name="app">The app builder</param>
        /// <param name="configurationAction">Configuration action</param>
        [Obsolete("Please use `GlobalConfiguration` class for configuration, or `IAppBuilder.UseHangfireDashboard` and `IAppBuilder.UseHangfireServer` OWIN extension methods instead. Will be removed in version 2.0.0.")]
        public static void UseHangfire(
            [NotNull] this IAppBuilder app,
            [NotNull] Action<IBootstrapperConfiguration> configurationAction)
        {
            if (app == null) throw new ArgumentNullException(nameof(app));
            if (configurationAction == null) throw new ArgumentNullException(nameof(configurationAction));

            var configuration = new BootstrapperConfiguration();
            configurationAction(configuration);

            if (configuration.Activator != null)
            {
                JobActivator.Current = configuration.Activator;
            }

            if (configuration.Storage != null)
            {
                JobStorage.Current = configuration.Storage;
            }

            foreach (var filter in configuration.Filters)
            {
                GlobalJobFilters.Filters.Add(filter);

View on GitHub (pinned to c236dd0f93)

Solutions

  1. Replace OwinBootstrapper.UseHangfire with GlobalConfiguration.Configuration.UseXXXStorage(...) plus IAppBuilder.UseHangfireDashboard/UseHangfireServer — the supported, non-obsolete path.
  2. Ensure UseHangfire is called on the non-null IAppBuilder received in Startup.Configuration(IAppBuilder app).
  3. Verify the OWIN host is properly initialized (e.g. WebApp.Start or the ASP.NET Katana host) so app is never null.

Example fix

// before
OwinBootstrapper.UseHangfire(null, cfg => cfg.UseSqlServerStorage(cs));

// after
GlobalConfiguration.Configuration.UseSqlServerStorage(cs);
app.UseHangfireDashboard();
app.UseHangfireServer();
Defensive patterns

Strategy: validation

Validate before calling

if (app == null) throw new ArgumentNullException(nameof(app));
// prefer the supported path:
GlobalConfiguration.Configuration.UseXXXStorage(cs);
app.UseHangfireDashboard();
app.UseHangfireServer();

Type guard

// _ = app ?? throw new ArgumentNullException(nameof(app));

Prevention

When it happens

Trigger: Calling OwinBootstrapper.UseHangfire(null, configurationAction) — i.e. the 'this IAppBuilder' receiver is null, typically because the Startup.Configuration method received a null app (hosting misconfiguration) or a field was not assigned.

Common situations: A Startup class whose Configuration method signature is wrong (so app is null); test code that bootstraps Hangfire without a real OWIN host; migration from OwinBootstrapper to GlobalConfiguration where the app reference was dropped mid-refactor.

Related errors


AI-assisted analysis of HangfireIO/Hangfire@c236dd0f93 (2026-08-13). Data as JSON: /api/errors/fb83553e12eac94f. Report an issue: GitHub.