{"record":{"id":"974cc86dddb95abd","repo":"dotnet/aspnetcore","slug":"no-renderer-has-been-initialized","errorCode":null,"errorMessage":"No renderer has been initialized.","messagePattern":"No renderer has been initialized\\.","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"src/Components/Components/src/RenderHandle.cs","lineNumber":64,"sourceCode":"    /// Gets a value that indicates whether the <see cref=\"RenderHandle\"/> has been\n    /// initialized and is ready to use.\n    /// </summary>\n    public bool IsInitialized => _renderer is not null;\n\n    /// <summary>\n    /// Gets a value that determines if the <see cref=\"Renderer\"/> is triggering a render in response to a metadata update (hot-reload) change.\n    /// </summary>\n    public bool IsRenderingOnMetadataUpdate => HotReloadManager.IsSupported && (_renderer?.IsRenderingOnMetadataUpdate ?? false);\n\n    internal bool IsFirstHotReloadRender() => IsRenderingOnMetadataUpdate && _renderer?.IsFirstHotReloadRender(_componentId) == true;\n\n    internal bool IsRendererDisposed => _renderer?.Disposed\n        ?? throw new InvalidOperationException(\"No renderer has been initialized.\");\n\n    /// <summary>\n    /// Gets the <see cref=\"Components.RendererInfo\"/> the component is running on.\n    /// </summary>\n    public RendererInfo RendererInfo => _renderer?.RendererInfo ?? throw new InvalidOperationException(\"No renderer has been initialized.\");\n\n    /// <summary>\n    /// Retrieves the <see cref=\"IComponentRenderMode\"/> assigned to the component.\n    /// </summary>\n    /// <returns>The <see cref=\"IComponentRenderMode\"/> assigned to the component.</returns>\n    public IComponentRenderMode? RenderMode\n    {\n        get\n        {\n            if (_renderer == null)\n            {\n                throw new InvalidOperationException(\"No renderer has been initialized.\");\n            }\n\n            return _renderer.GetComponentRenderMode(_componentId);\n        }\n    }\n","sourceCodeStart":46,"sourceCodeEnd":82,"githubUrl":"https://github.com/dotnet/aspnetcore/blob/294cab2f9b2e03af6b953820c7ab497c3c8b7ad9/src/Components/Components/src/RenderHandle.cs#L46-L82","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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."],"exampleFix":"// before (test)\nvar component = new MyComponent(); // RenderHandle never set\nvar info = component.RendererInfo; // throws\n\n// after (bUnit)\nusing var ctx = new TestContext();\nvar cut = ctx.RenderComponent<MyComponent>();\n// RendererInfo accessible inside component lifecycle","handlingStrategy":"type-guard","validationCode":"if (renderHandle.IsInitialized)\n{\n    var info = renderHandle.RendererInfo;\n}","typeGuard":"// Guard before accessing RendererInfo\nstatic RendererInfo? SafeGetRendererInfo(RenderHandle handle)\n    => handle.IsInitialized ? handle.RendererInfo : null;","tryCatchPattern":null,"preventionTips":["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."],"tags":["blazor","renderhandle","renderer","lifecycle","testing"],"analyzedSha":"294cab2f9b2e03af6b953820c7ab497c3c8b7ad9","analyzedAt":"2026-08-06T20:08:02.189Z","schemaVersion":2},"datasetVersion":"2026-08-06T23:17:07.152Z"}