dotnet/aspnetcore · error · InvalidOperationException
The component type '{componentType}' has a fixed rendermode
Error message
The component type '{componentType}' has a fixed rendermode of '{componentTypeRenderMode}', so it is not valid to specify any rendermode when using this component. What it means
Thrown by ComponentFactory.InstantiateComponent when a component type has a [RenderMode] attribute (giving it a fixed render mode) AND the call site also specifies a render mode via @rendermode. The framework resolves exactly one render mode; when the type itself declares one, the caller must not supply another. The conflict is detected at ComponentFactory.cs:70-74.
Source
Thrown at src/Components/Components/src/ComponentFactory.cs:74
public IComponent InstantiateComponent(IServiceProvider serviceProvider, [DynamicallyAccessedMembers(Component)] Type componentType, IComponentRenderMode? callerSpecifiedRenderMode, int? parentComponentId)
{
var componentTypeRenderMode = GetComponentTypeRenderMode(componentType);
IComponent component;
if (componentTypeRenderMode is null && callerSpecifiedRenderMode is null)
{
// Typical case where no rendermode is specified in either location. We don't call ResolveComponentForRenderMode in this case.
component = _componentActivator.CreateInstance(componentType);
}
else
{
// At least one rendermode is specified. We require that it's exactly one, and use ResolveComponentForRenderMode with it.
var effectiveRenderMode = callerSpecifiedRenderMode is null
? componentTypeRenderMode!
: componentTypeRenderMode is null
? callerSpecifiedRenderMode
: throw new InvalidOperationException($"The component type '{componentType}' has a fixed rendermode of '{componentTypeRenderMode}', so it is not valid to specify any rendermode when using this component.");
component = _renderer.ResolveComponentForRenderMode(componentType, parentComponentId, _componentActivator, effectiveRenderMode);
}
if (component is null)
{
// The default activator/resolver will never do this, but an externally-supplied one might
throw new InvalidOperationException($"The component activator returned a null value for a component of type {componentType.FullName}.");
}
if (!_propertyInjectionDisabled)
{
PerformPropertyInjection(serviceProvider, component);
}
return component;
}
private void PerformPropertyInjection(IServiceProvider serviceProvider, IComponent instance)View on GitHub (pinned to 294cab2f9b)
Solutions
- Remove the @rendermode from the call site — let the component's own [RenderMode] attribute win.
- Or remove the [RenderMode] attribute from the component type if callers need to choose.
- Do not specify render mode in both places.
Example fix
// before
// Component definition
[RenderMode(InteractiveServer)]
public class MyComponent : ComponentBase { }
// Usage (conflict)
<MyComponent @rendermode="InteractiveWebAssembly" />
// after — remove the caller-side mode
<MyComponent /> Defensive patterns
Strategy: validation
Validate before calling
var typeRenderMode = componentType.GetCustomAttribute<RenderModeAttribute>()?.Mode;
if (typeRenderMode is not null && callerSpecifiedRenderMode is not null)
throw new InvalidOperationException("Component has a fixed rendermode; do not specify @rendermode at call site."); Prevention
- Choose render mode in one place: either the component attribute or the call site, never both.
- Document which components are pinned to a render mode.
When it happens
Trigger: A component decorated with [RenderMode(InteractiveServer)] (or similar) is referenced with an explicit @rendermode="..." in markup. The ternary at line 70-74 throws when neither side is null.
Common situations: Applying [RenderMode] at the component level and also setting @rendermode at the call site; library components that pin their own render mode being used with a caller-specified mode.
Related errors
- Cannot supply a component of type '{componentType}' because
- Dynamic root components have already been enabled.
- Root components cannot be marked as interactive. The <html>
- Only one interactive runtime may enable navigation intercept
- Unexpected renderer ID '${rendererId}' encountered while dis
AI-assisted analysis of dotnet/aspnetcore@294cab2f9b (2026-08-06).
Data as JSON: /api/errors/514796de0b3d7cd3.
Report an issue: GitHub.