HangfireIO/Hangfire · error · ArgumentException

Resource with name {resourceName} not found in assembly {ass

Error message

Resource with name {resourceName} not found in assembly {assembly}.

What it means

EmbeddedResourceDispatcher.WriteResource (EmbeddedResourceDispatcher.cs:61) looks up a manifest resource stream by name within an assembly. If GetManifestResourceStream returns null the resource name does not match any embedded resource in that assembly (names are case-sensitive and include the default namespace prefix), and an ArgumentException is thrown.

Source

Thrown at src/Hangfire.Core/Dashboard/EmbeddedResourceDispatcher.cs:61

            context.Response.ContentType = _contentType;
            context.Response.SetExpire(DateTimeOffset.Now.AddYears(1));

            await WriteResponse(context.Response).ConfigureAwait(false);
        }

        protected virtual Task WriteResponse(DashboardResponse response)
        {
            return WriteResource(response, _assembly, _resourceName);
        }

        [System.Diagnostics.CodeAnalysis.SuppressMessage("Performance", "CA1822:Mark members as static", Justification = "Context can be potentially accessed in derived classes.")]
        protected async Task WriteResource(DashboardResponse response, Assembly assembly, string resourceName)
        {
            using (var inputStream = assembly.GetManifestResourceStream(resourceName))
            {
                if (inputStream == null)
                {
                    throw new ArgumentException($@"Resource with name {resourceName} not found in assembly {assembly}.");
                }

                await inputStream.CopyToAsync(response.Body).ConfigureAwait(false);
            }
        }
    }
}

View on GitHub (pinned to c236dd0f93)

Solutions

  1. Enumerate assembly.GetManifestResourceNames() and use the exact returned string.
  2. Ensure the resource file's Build Action is 'Embedded Resource' in the .csproj.
  3. Prefix the resource name with the project's default namespace (e.g. 'MyApp.Assets.style.css').
  4. Pass the correct assembly instance (typeof(LocalType).Assembly) rather than a different assembly.

Example fix

// before
app.UseHangfireDashboard("/dashboard", new DashboardOptions
{
    AdditionalData = new[]
    {
        new EmbeddedResourceDispatcher(typeof(Startup).Assembly, "assets.css")
    }
});

// after
var assembly = typeof(Startup).Assembly;
var name = assembly.GetManifestResourceNames()
    .First(n => n.EndsWith("assets.css"));
var dispatcher = new EmbeddedResourceDispatcher(assembly, name);
Defensive patterns

Strategy: validation

Validate before calling

var assembly = typeof(Startup).Assembly;
var available = assembly.GetManifestResourceNames();
if (!available.Contains(resourceName, StringComparer.Ordinal))
    throw new ArgumentException(
        $"Resource '{resourceName}' not found. Available: {string.Join(", ", available)}");

Prevention

When it happens

Trigger: Registering a dashboard route with an EmbeddedResourceDispatcher(assembly, resourceName) where resourceName does not exactly match the full manifest resource name (including namespace) in the given assembly.

Common situations: Default namespace differs from assembly name; resource file was moved or renamed; project uses a custom root namespace; the resource's Build Action is not set to 'Embedded Resource'; casing mismatch between the passed name and the manifest name.

Related errors


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