dotnet/aspnetcore · error · ArgumentException

The component type must implement {typeof(IComponent).FullNa

Error message

The component type must implement {typeof(IComponent).FullName}.

What it means

OpenComponent(int sequence, Type componentType) was called with a type that does not implement IComponent. Components must implement IComponent to be renderable; the builder validates with typeof(IComponent).IsAssignableFrom(componentType).

Source

Thrown at src/Components/Components/src/Rendering/RenderTreeBuilder.cs:506

    /// <summary>
    /// Appends a frame representing a child component.
    /// </summary>
    /// <typeparam name="TComponent">The type of the child component.</typeparam>
    /// <param name="sequence">An integer that represents the position of the instruction in the source code.</param>
    public void OpenComponent<[DynamicallyAccessedMembers(Component)] TComponent>(int sequence) where TComponent : notnull, IComponent
        => OpenComponentUnchecked(sequence, typeof(TComponent));

    /// <summary>
    /// Appends a frame representing a child component.
    /// </summary>
    /// <param name="sequence">An integer that represents the position of the instruction in the source code.</param>
    /// <param name="componentType">The type of the child component.</param>
    public void OpenComponent(int sequence, [DynamicallyAccessedMembers(Component)] Type componentType)
    {
        if (!typeof(IComponent).IsAssignableFrom(componentType))
        {
            throw new ArgumentException($"The component type must implement {typeof(IComponent).FullName}.");
        }

        OpenComponentUnchecked(sequence, componentType);
    }

    /// <summary>
    /// Appends a frame representing a component parameter.
    /// </summary>
    /// <param name="sequence">An integer that represents the position of the instruction in the source code.</param>
    /// <param name="name">The name of the attribute.</param>
    /// <param name="value">The value of the attribute.</param>
    public void AddComponentParameter(int sequence, string name, object? value)
    {
        AssertCanAddComponentParameter();
        _entries.AppendAttribute(sequence, name, value);
    }

    /// <summary>

View on GitHub (pinned to 3600ca084e)

Solutions

  1. Verify the type implements IComponent (inherits ComponentBase or implements IComponent directly).
  2. Constrain generic parameters with `where TComponent : IComponent`.
  3. Add a runtime guard before calling OpenComponent: if (!typeof(IComponent).IsAssignableFrom(t)) throw a clearer error.

Example fix

// before
builder.OpenComponent(0, typeof(MyPlainViewModel));

// after
builder.OpenComponent(0, typeof(MyRazorComponent)); // MyRazorComponent : ComponentBase
Defensive patterns

Strategy: type-guard

Validate before calling

if (!typeof(IComponent).IsAssignableFrom(componentType))
    throw new ArgumentException($"{componentType} is not an IComponent.");
builder.OpenComponent(seq, componentType);

Type guard

static bool IsComponentType(Type t) => typeof(IComponent).IsAssignableFrom(t);

Prevention

When it happens

Trigger: Passing a POCO, interface, or arbitrary runtime Type into OpenComponent. Reflectively choosing a component type and getting the wrong one. Generic dispatch where TComponent was unconstrained and slipped through.

Common situations: Dynamic component rendering where the type comes from configuration/reflection. Migrating a class to be a component but forgetting to implement IComponent. Wrong type passed to a generic <DynamicComponent>. Unit tests with mock types.

Related errors


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