dotnet/aspnetcore · error · InvalidOperationException

The {nameof(Router)} component requires a value for the para

Error message

The {nameof(Router)} component requires a value for the parameter {nameof(AppAssembly)}.

What it means

The Router component requires AppAssembly (or AdditionalAssemblies) to know where to scan for [Route]-attributed page components. SetParametersAsync throws InvalidOperationException if AppAssembly is null on first parameter set, because without an assembly there is no route table to consult. The check runs before any rendering so the misconfiguration fails fast.

Source

Thrown at src/Components/Components/src/Routing/Router.cs:127

        _locationAbsolute = NavigationManager.Uri;
        NavigationManager.LocationChanged += OnLocationChanged;
        NavigationManager.OnNotFound += OnNotFound;
        RoutingStateProvider = ServiceProvider.GetService<IRoutingStateProvider>();

        if (HotReloadManager.IsSupported)
        {
            HotReloadManager.Default.OnDeltaApplied += ClearRouteCaches;
        }
    }

    /// <inheritdoc />
    public async Task SetParametersAsync(ParameterView parameters)
    {
        parameters.SetParameterProperties(this);

        if (AppAssembly == null)
        {
            throw new InvalidOperationException($"The {nameof(Router)} component requires a value for the parameter {nameof(AppAssembly)}.");
        }

        // Found content is mandatory, because even though we could use something like <RouteView ...> as a
        // reasonable default, if it's not declared explicitly in the template then people will have no way
        // to discover how to customize this (e.g., to add authorization).
        if (Found == null)
        {
            throw new InvalidOperationException($"The {nameof(Router)} component requires a value for the parameter {nameof(Found)}.");
        }

        if (NotFoundPage != null)
        {
#pragma warning disable CS0618 // Type or member is obsolete
            if (NotFound != null)
            {
                throw new InvalidOperationException($"Setting {nameof(NotFound)} and {nameof(NotFoundPage)} properties simultaneously is not supported. Use either {nameof(NotFound)} or {nameof(NotFoundPage)}.");
            }
#pragma warning restore CS0618 // Type or member is obsolete

View on GitHub (pinned to 3600ca084e)

Solutions

  1. Set AppAssembly on the Router, typically AppAssembly="@typeof(Program).Assembly" or @typeof(SomeType).Assembly.
  2. If your pages live in multiple assemblies, also set AdditionalAssemblies with the full list.
  3. Verify the typeof target compiles and the assembly it points to actually contains your @page components.
  4. Add an integration test that renders App.razor to catch missing AppAssembly early.

Example fix

// before (App.razor)
<Router>
    <Found Context="routeData"><RouteView RouteData="@routeData" /></Found>
</Router>
// after
<Router AppAssembly="@typeof(Program).Assembly">
    <Found Context="routeData"><RouteView RouteData="@routeData" /></Found>
</Router>
Defensive patterns

Strategy: validation

Validate before calling

// In App.razor, always supply AppAssembly. Validate at startup:
var asm = typeof(Program).Assembly;
if (asm is null) throw new InvalidOperationException("Program assembly not resolvable.");

Prevention

When it happens

Trigger: Declaring <Router>...</Router> without an AppAssembly attribute, or binding AppAssembly to an expression that resolves to null (e.g. a static that has not been initialized). Also triggered by manually constructing Router and calling SetParametersAsync without AppAssembly.

Common situations: Starting a new Blazor project and editing App.razor without setting AppAssembly; renaming the assembly and forgetting to update @inject or the typeof expression; refactoring the Router markup and dropping the attribute; binding to a property that is conditionally initialized.

Related errors


AI-assisted analysis of dotnet/aspnetcore@3600ca084e (2026-08-11). Data as JSON: /api/errors/66a13869e0852260. Report an issue: GitHub.