dotnet/aspnetcore · error · InvalidOperationException

The type {context.Handler.FullName} does not implement Micro

Error message

The type {context.Handler.FullName} does not implement Microsoft.AspNetCore.Components.IComponent.

What it means

Thrown in Router.Refresh after a route matches: context.Handler is the type matched by the URL, but it does not implement IComponent. The Router only renders Blazor components, so a [Route]-decorated non-component type matched during navigation is a configuration error, not a renderable page.

Source

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

            _renderHandle.Render(Found(endpointRouteData));

            if (ComponentsActivitySource.IsSupported && _renderHandle.ComponentActivitySource != null)
            {
                _renderHandle.ComponentActivitySource.StopNavigateActivity(activityHandle, null);
            }
            return;
        }

        RefreshRouteTable();

        var context = new RouteContext(locationPath);
        Routes.Route(context);

        if (context.Handler != null)
        {
            if (!typeof(IComponent).IsAssignableFrom(context.Handler))
            {
                throw new InvalidOperationException($"The type {context.Handler.FullName} " +
                    $"does not implement {typeof(IComponent).FullName}.");
            }

            activityHandle = RecordDiagnostics(context.Handler.FullName, context.Entry.RoutePattern.RawText);

            Log.NavigatingToComponent(_logger, context.Handler, locationPath, _baseUri);

            var routeData = new RouteData(
                context.Handler,
                context.Parameters ?? _emptyParametersDictionary);

            _renderHandle.Render(Found(routeData));

            // If you navigate to a different path, then after the next render we'll update the scroll position
            if (relativePath != _updateScrollPositionForHashLastLocation)
            {
                _updateScrollPositionForHashLastLocation = relativePath.ToString();
                _updateScrollPositionForHash = true;

View on GitHub (pinned to 294cab2f9b)

Solutions

  1. Identify the matched type from the exception (context.Handler.FullName) and remove its [Route] attribute or move it out of the Router-scanned assembly.
  2. Make sure only Blazor components carry Microsoft.AspNetCore.Components.RouteAttribute in AppAssembly/AdditionalAssemblies.
  3. If the type should be a Blazor page, make it implement IComponent (e.g., convert it to a .razor component with @page).

Example fix

// before: a non-component type in a Blazor-scanned assembly
[Route("/legacy")]
public class LegacyHandler { /* MVC-style, not IComponent */ }

// after: move it out of the scanned assembly, or convert to a component
// Legacy.razor
@page "/legacy"
Defensive patterns

Strategy: validation

Validate before calling

// Filter the assemblies the Router scans so only IComponent types with Components [Route] are matched.
static IEnumerable<Type> BlazorRoutes(params Assembly[] assemblies) =>
    assemblies.SelectMany(a => a.GetTypes())
        .Where(t => typeof(IComponent).IsAssignableFrom(t))
        .Where(t => t.GetCustomAttributes(typeof(RouteAttribute), true).Length > 0);
// Ensure non-component [Route]-bearing types (MVC handlers, etc.) are not in AppAssembly/AdditionalAssemblies.

Type guard

static bool IsBlazorRoutable(Type t) =>
    typeof(IComponent).IsAssignableFrom(t) &&
    t.GetCustomAttributes(typeof(Microsoft.AspNetCore.Components.RouteAttribute), true).Length > 0;

Prevention

When it happens

Trigger: A type in AppAssembly (or AdditionalAssemblies) decorated with [Route("/path")] but not implementing IComponent (e.g., an ASP.NET Core MVC/Razor Pages route attribute leaking into the Blazor-scanned assembly, or a class with [Route] by mistake). Navigating to that path triggers the throw.

Common situations: Mixing MVC [Route] and Blazor [Route] (Microsoft.AspNetCore.Mvc.Routing vs Microsoft.AspNetCore.Components) in the same assembly; an old Razor Pages/MVC handler left in an assembly scanned by the Blazor Router; a shared library referenced by both stacks.

Related errors


AI-assisted analysis of dotnet/aspnetcore@294cab2f9b (2026-08-06). Data as JSON: /api/errors/569a109532439759. Report an issue: GitHub.