HangfireIO/Hangfire · error · ArgumentNullException

assembly

Error message

assembly

What it means

UseDashboardStylesheet registers an embedded CSS resource for the Hangfire dashboard via DashboardRoutes.AddStylesheet(assembly, resource). The `assembly` argument identifies the assembly containing the embedded resource stream. Hangfire guards it with ArgumentNullException(nameof(assembly)) because AddStylesheet needs a concrete Assembly to call GetManifestResourceStream on. A null assembly means the resource lookup has no source to read from.

Source

Thrown at src/Hangfire.Core/GlobalConfigurationExtensions.cs:393

        }

        public static IGlobalConfiguration UseDefaultCulture(
            [NotNull] this IGlobalConfiguration configuration,
            [CanBeNull] CultureInfo culture,
            [CanBeNull] CultureInfo uiCulture,
            bool captureDefault)
        {
            if (configuration == null) throw new ArgumentNullException(nameof(configuration));
            return configuration.UseFilter(new CaptureCultureAttribute(culture?.Name, uiCulture?.Name, captureDefault));
        }

        public static IGlobalConfiguration UseDashboardStylesheet(
            [NotNull] this IGlobalConfiguration configuration,
            [NotNull] Assembly assembly,
            [NotNull] string resource)
        {
            if (configuration == null) throw new ArgumentNullException(nameof(configuration));
            if (assembly == null) throw new ArgumentNullException(nameof(assembly));
            if (resource == null) throw new ArgumentNullException(nameof(resource));

            DashboardRoutes.AddStylesheet(assembly, resource);
            return configuration;
        }

        public static IGlobalConfiguration UseDashboardStylesheetDarkMode(
            [NotNull] this IGlobalConfiguration configuration,
            [NotNull] Assembly assembly,
            [NotNull] string resource)
        {
            if (configuration == null) throw new ArgumentNullException(nameof(configuration));
            if (assembly == null) throw new ArgumentNullException(nameof(assembly));
            if (resource == null) throw new ArgumentNullException(nameof(resource));

            DashboardRoutes.AddStylesheetDarkMode(assembly, resource);
            return configuration;
        }

View on GitHub (pinned to c236dd0f93)

Solutions

  1. Pass a concrete assembly: `typeof(Startup).Assembly` or `Assembly.GetExecutingAssembly()` instead of a possibly-null value.
  2. Avoid `Assembly.GetEntryAssembly()` for resource lookups, or guard it: `var asm = Assembly.GetEntryAssembly() ?? typeof(Startup).Assembly;`
  3. Validate the assembly is non-null before calling: `ArgumentNullException.ThrowIfNull(assembly);`
  4. Confirm the resource string matches an actual `[assembly: EmbeddedResource]`/manifest resource name in that assembly.

Example fix

// before
GlobalConfiguration.Configuration.UseDashboardStylesheet(
    Assembly.GetEntryAssembly(), // null in some hosts => ANE(assembly)
    "MyApp.styles.min.css");

// after
GlobalConfiguration.Configuration.UseDashboardStylesheet(
    typeof(Startup).Assembly,
    "MyApp.styles.min.css");
Defensive patterns

Strategy: validation

Validate before calling

ArgumentNullException.ThrowIfNull(assembly);
// Avoid Assembly.GetEntryAssembly() when it may be null:
var asm = assembly ?? typeof(Startup).Assembly;
GlobalConfiguration.Configuration.UseDashboardStylesheet(asm, resource);

Type guard

static Assembly ResolveAssembly()
    => Assembly.GetEntryAssembly() ?? Assembly.GetExecutingAssembly();

static bool IsAssemblyAvailable(Assembly? a) => a is not null;

Try / catch

try { configuration.UseDashboardStylesheet(assembly, resource); }
catch (ArgumentNullException ex) when (ex.ParamName == "assembly")
{ throw new InvalidOperationException(
    "Dashboard stylesheet assembly is null; use typeof(Startup).Assembly instead of Assembly.GetEntryAssembly().", ex); }

Prevention

When it happens

Trigger: Calling `.UseDashboardStylesheet(config, assembly, "My.Style.css")` where `assembly` is null — e.g. `Assembly.GetEntryAssembly()` returned null (common in some in-proc/test hosts and certain ASP.NET Classic hosting scenarios), or the developer passed `null` instead of `typeof(Startup).Assembly` / `Assembly.GetExecutingAssembly()`.

Common situations: Using `Assembly.GetEntryAssembly()` which returns null in some test runners, IIS-hosted apps without an entry assembly, or worker scenarios; a dynamically-loaded assembly that failed to load and was left null; copy-pasting the stylesheet registration call but forgetting to fill in the assembly argument; third-party dashboard themes that resolve their assembly from a nullable field.

Related errors


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