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
- Verify the type implements IComponent (inherits ComponentBase or implements IComponent directly).
- Constrain generic parameters with `where TComponent : IComponent`.
- 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
- Constrain generics: `where TComponent : IComponent`.
- For dynamic types, validate IsAssignableFrom before OpenComponent.
- Prefer inheriting ComponentBase over implementing IComponent from scratch.
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
- Valueless attributes may only be added immediately after fra
- The {nameof(frame.FrameType)} must be {RenderTreeFrameType.A
- No preceding attribute frame exists.
- The type {componentType.FullName} does not implement {nameof
- Invalid layout type: {layoutType.FullName} does not implemen
AI-assisted analysis of dotnet/aspnetcore@3600ca084e (2026-08-11).
Data as JSON: /api/errors/c5b91201ebe91121.
Report an issue: GitHub.