dotnet/aspnetcore · error · ArgumentException
The type does not implement .
Error message
The type {componentType.FullName} does not implement {nameof(IComponent)}. What it means
DefaultComponentActivator.CreateInstance requires the supplied type to implement IComponent, the fundamental Blazor contract. Passing a plain class, record, or any non-component type is rejected with ArgumentException.
Solutions
- Ensure the type implements IComponent (inherit from ComponentBase or implement IComponent directly).
- Validate typeof(IComponent).IsAssignableFrom(type) before activating.
- If using DynamicComponent, guard the Type with a null/contract check.
Example fix
// before DynamicComponent with Type = typeof(SomePlainClass) // after DynamicComponent with Type = typeof(SomeRazorComponent) // SomeRazorComponent : ComponentBase
Defensive patterns
Strategy: type-guard
Validate before calling
if (!typeof(IComponent).IsAssignableFrom(componentType))
throw new ArgumentException($"{componentType} is not an IComponent."); Type guard
static bool IsComponent(Type t) => typeof(IComponent).IsAssignableFrom(t);
Prevention
- Validate typeof(IComponent).IsAssignableFrom before activating or assigning to DynamicComponent.Type.
- Constrain DynamicComponent Type sources to known component assemblies.
- Unit-test that candidate types implement IComponent.
When it happens
Trigger: Calling CreateInstance with a Type that does not implement IComponent, e.g. via DynamicComponent's Type parameter set to a non-component, or reflection-driven activation with an arbitrary type.
Common situations: DynamicComponent bound to a type resolved at runtime that is not a component, or a custom activator forwarding arbitrary types to the default activator.
Related errors
- Invalid layout type: does not implement .
- does not accept a parameter with the name ' '. To pass…
- requires a non-null value for the parameter .
- The component activator returned a null value for a…
- The component type must implement
AI-assisted analysis of dotnet/aspnetcore@3600ca084e (2026-08-11).
Data as JSON: /api/errors/3c800d0389c070f7.
Report an issue: GitHub.
Appendix: source
Thrown at src/Components/Components/src/DefaultComponentActivator.cs:30
{
private static readonly ConcurrentDictionary<Type, ObjectFactory> _cachedComponentTypeInfo = new();
static DefaultComponentActivator()
{
if (HotReloadManager.IsSupported)
{
HotReloadManager.Default.OnDeltaApplied += ClearCache;
}
}
public static void ClearCache() => _cachedComponentTypeInfo.Clear();
/// <inheritdoc />
public IComponent CreateInstance([DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors)] Type componentType)
{
if (!typeof(IComponent).IsAssignableFrom(componentType))
{
throw new ArgumentException($"The type {componentType.FullName} does not implement {nameof(IComponent)}.", nameof(componentType));
}
var factory = GetObjectFactory(componentType);
return (IComponent)factory(serviceProvider, []);
}
private static ObjectFactory GetObjectFactory([DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors)] Type componentType)
{
// Unfortunately we can't use 'GetOrAdd' here because the DynamicallyAccessedMembers annotation doesn't flow through to the
// callback, so it becomes an IL2111 warning. The following is equivalent and thread-safe because it's a ConcurrentDictionary
// and it doesn't matter if we build a cache entry more than once.
if (!_cachedComponentTypeInfo.TryGetValue(componentType, out var factory))
{
factory = ActivatorUtilities.CreateFactory(componentType, Type.EmptyTypes);
_cachedComponentTypeInfo.TryAdd(componentType, factory);
}
View on GitHub (pinned to 3600ca084e)