{"record":{"id":"05156d9f622a1fde","repo":"dotnet/aspnetcore","slug":"dynamic-root-components-have-not-been-enabled-in-t","errorCode":null,"errorMessage":"Dynamic root components have not been enabled in this application.","messagePattern":"Dynamic root components have not been enabled in this application\\.","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/Components/Web.JS/src/Rendering/JSRootComponents.ts","lineNumber":158,"sourceCode":"  if (!hasInitializedJsComponents) {\n    // Call the registered initializers. This is an arbitrary subset of the JS component types that are registered\n    // on the .NET side - just those of them that require some JS-side initialization (e.g., to register them\n    // as custom elements).\n    for (const [initializerIdentifier, componentIdentifiers] of Object.entries(jsComponentInitializers)) {\n      const initializerFunc = DotNet.findJSFunction(initializerIdentifier, 0) as JSComponentInitializerCallback;\n      for (const componentIdentifier of componentIdentifiers) {\n        const parameters = jsComponentParameters[componentIdentifier];\n        initializerFunc(componentIdentifier, parameters);\n      }\n    }\n\n    hasInitializedJsComponents = true;\n  }\n}\n\nfunction getRequiredManager(): DotNet.DotNetObject {\n  if (!manager) {\n    throw new Error('Dynamic root components have not been enabled in this application.');\n  }\n\n  return manager;\n}\n\n// Keep in sync with equivalent in JSComponentConfigurationStore.cs\n// These are an internal implementation detail not exposed in the registration APIs.\nexport type JSComponentParametersByIdentifier = { [identifier: string]: JSComponentParameter[] };\nexport type JSComponentIdentifiersByInitializer = { [initializer: string]: string[] };\n\n// The following is public API\nexport interface JSComponentInitializerCallback {\n  (identifier: string, parameters: JSComponentParameter[]): void;\n}\n\nexport interface JSComponentParameter {\n  name: string;\n  type: JSComponentParameterType;","sourceCodeStart":140,"sourceCodeEnd":176,"githubUrl":"https://github.com/dotnet/aspnetcore/blob/3600ca084e9c8b5f4174fc5e747f4c52d2100806/src/Components/Web.JS/src/Rendering/JSRootComponents.ts#L140-L176","documentation":"Thrown by getRequiredManager when the module-level manager is unset, i.e. enableJSRootComponents was never called for this page. Dynamic root component APIs (add) need a live .NET DotNetObjectReference to invoke AddRootComponent; without it the operation cannot proceed. This typically means JS component initialization was not wired up.","triggerScenarios":"Calling Blazor.rootComponents.add before Blazor has started; using add in an app that did not register JSComponentInitializer callbacks; calling during prerender before the circuit is established.","commonSituations":"Calling add in a script that runs before Blazor.start resolves; an app not configured for JSRootComponents; an early DOMContentLoaded handler racing the framework.","solutions":["Await Blazor.start() before calling rootComponents.add.","Ensure the app is a Blazor Server or WebAssembly interactive host (JS root components require an interactive renderer).","Move the registration into a JSInitializer that the framework calls after startup.","Verify AddComponent support is enabled in the .NET host configuration."],"exampleFix":"// before (throws)\nBlazor.rootComponents.add(el, 'MyComponent', {});\n\n// after\nawait Blazor.start();\nawait Blazor.rootComponents.add(el, 'MyComponent', {});","handlingStrategy":"validation","validationCode":"if (!Blazor.rootComponents) {\n  throw new Error('JS root components are not enabled; check your host configuration.');\n}\nawait Blazor.start();\nawait Blazor.rootComponents.add(el, id, params);","typeGuard":null,"tryCatchPattern":"try {\n  await Blazor.rootComponents.add(el, id, params);\n} catch (e) {\n  if (/not been enabled/.test(String(e?.message))) {\n    await Blazor.start();\n    await Blazor.rootComponents.add(el, id, params);\n  } else { throw e; }\n}","preventionTips":["Always await Blazor.start() before calling rootComponents APIs.","Perform registration inside a JSInitializer invoked by the framework.","Confirm the app is configured for interactive rendering."],"tags":["blazor","root-components","startup","lifecycle"],"backgroundTag":null,"analyzedSha":"3600ca084e9c8b5f4174fc5e747f4c52d2100806","analyzedAt":"2026-08-11T16:32:30.678Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}