dotnet/aspnetcore · error · InvalidOperationException
No renderer has been initialized.
Error message
No renderer has been initialized.
What it means
The RenderHandle.RendererInfo property returns metadata about the platform the component is running on (e.g., whether it is Server, WebAssembly, or Static SSR). It throws InvalidOperationException when the internal _renderer field is null, which means the RenderHandle struct was never initialized by a Renderer instance. This almost always indicates the component was instantiated outside the normal Blazor rendering pipeline.
Source
Thrown at src/Components/Components/src/RenderHandle.cs:64
/// Gets a value that indicates whether the <see cref="RenderHandle"/> has been
/// initialized and is ready to use.
/// </summary>
public bool IsInitialized => _renderer is not null;
/// <summary>
/// Gets a value that determines if the <see cref="Renderer"/> is triggering a render in response to a metadata update (hot-reload) change.
/// </summary>
public bool IsRenderingOnMetadataUpdate => HotReloadManager.IsSupported && (_renderer?.IsRenderingOnMetadataUpdate ?? false);
internal bool IsFirstHotReloadRender() => IsRenderingOnMetadataUpdate && _renderer?.IsFirstHotReloadRender(_componentId) == true;
internal bool IsRendererDisposed => _renderer?.Disposed
?? throw new InvalidOperationException("No renderer has been initialized.");
/// <summary>
/// Gets the <see cref="Components.RendererInfo"/> the component is running on.
/// </summary>
public RendererInfo RendererInfo => _renderer?.RendererInfo ?? throw new InvalidOperationException("No renderer has been initialized.");
/// <summary>
/// Retrieves the <see cref="IComponentRenderMode"/> assigned to the component.
/// </summary>
/// <returns>The <see cref="IComponentRenderMode"/> assigned to the component.</returns>
public IComponentRenderMode? RenderMode
{
get
{
if (_renderer == null)
{
throw new InvalidOperationException("No renderer has been initialized.");
}
return _renderer.GetComponentRenderMode(_componentId);
}
}
View on GitHub (pinned to 294cab2f9b)
Solutions
- If testing, use a test renderer such as TestRenderer or bUnit's TestContext that properly initializes the RenderHandle.
- Avoid accessing RendererInfo (or any renderer-dependent property) before the component has been attached to a renderer.
- Check RenderHandle.IsInitialized before accessing renderer-dependent properties.
- Ensure the component is registered through the normal component rendering pipeline (ComponentsApplicationBuilder, Router, or a host component) rather than instantiated directly.
Example fix
// before (test) var component = new MyComponent(); // RenderHandle never set var info = component.RendererInfo; // throws // after (bUnit) using var ctx = new TestContext(); var cut = ctx.RenderComponent<MyComponent>(); // RendererInfo accessible inside component lifecycle
Defensive patterns
Strategy: type-guard
Validate before calling
if (renderHandle.IsInitialized)
{
var info = renderHandle.RendererInfo;
} Type guard
// Guard before accessing RendererInfo
static RendererInfo? SafeGetRendererInfo(RenderHandle handle)
=> handle.IsInitialized ? handle.RendererInfo : null; Prevention
- Always check RenderHandle.IsInitialized before accessing renderer-dependent properties.
- Use a test renderer (TestRenderer, bUnit TestContext) in unit tests rather than constructing components directly.
- Never access RenderHandle properties from a component constructor.
- Document which component methods require an initialized render handle.
When it happens
Trigger: Accessing component.RendererInfo (directly or transitively) on a RenderHandle created via default(RenderHandle), or on a component instantiated with new MyComponent() rather than through a Renderer. This can also occur in test harnesses that fail to wire up the render handle through TestRenderer or a bUnit TestContext.
Common situations: Unit tests that construct components manually without a test renderer; library code that attempts to create and render a component outside a host; using a component's RenderHandle-dependent API before the renderer has called the component's initialization.
Related errors
- The render handle is not yet assigned.
- Interop methods are already registered for renderer ${render
- Interop methods are not registered for renderer ${rendererId
- No interop methods are registered for renderer ${rendererId}
- Renderer with ID '${rendererId}' is not listening for naviga
AI-assisted analysis of dotnet/aspnetcore@294cab2f9b (2026-08-06).
Data as JSON: /api/errors/974cc86dddb95abd.
Report an issue: GitHub.