HangfireIO/Hangfire · error · ArgumentNullException

context

Error message

context

What it means

The UrlHelper(DashboardContext) constructor (UrlHelper.cs:39) throws ArgumentNullException when context is null. The helper needs a DashboardContext to resolve the request path base and options prefix for URL generation throughout the dashboard.

Source

Thrown at src/Hangfire.Core/Dashboard/UrlHelper.cs:39

{
    public class UrlHelper
    {
#if FEATURE_OWIN
        private readonly Microsoft.Owin.OwinContext _owinContext;

        [Obsolete("Please use UrlHelper(DashboardContext) instead. Will be removed in 2.0.0.")]
        public UrlHelper([NotNull] IDictionary<string, object> owinEnvironment)
        {
            if (owinEnvironment == null) throw new ArgumentNullException(nameof(owinEnvironment));
            _owinContext = new Microsoft.Owin.OwinContext(owinEnvironment);
        }
#endif

        private readonly DashboardContext _context;

        public UrlHelper([NotNull] DashboardContext context)
        {
            if (context == null) throw new ArgumentNullException(nameof(context));
            _context = context;
        }

        public string To(string relativePath)
        {
            return _context.Options.PrefixPath +
                   (
#if FEATURE_OWIN
                       _owinContext?.Request.PathBase.Value ??
#endif
                       _context.Request.PathBase
                   ) + relativePath;
        }

        public string Home()
        {
            return To("/");
        }

View on GitHub (pinned to c236dd0f93)

Solutions

  1. Ensure a valid DashboardContext is passed; obtain it from the dashboard request pipeline rather than constructing separately.
  2. Defer UrlHelper creation until the DashboardContext is available.

Example fix

// before
var helper = new UrlHelper(null);

// after
var helper = new UrlHelper(dashboardContext);
Defensive patterns

Strategy: validation

Validate before calling

if (context == null)
    throw new ArgumentNullException(nameof(context));
var helper = new UrlHelper(context);

Prevention

When it happens

Trigger: Instantiating new UrlHelper(null) via the DashboardContext overload.

Common situations: Custom dashboard page or middleware passing a null DashboardContext; context variable not yet initialized at the call site.

Related errors


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