{"record":{"id":"4fa762bf46f52514","repo":"dotnet/aspnetcore","slug":"circuit-host-not-initialized","errorCode":null,"errorMessage":"Circuit host not initialized.","messagePattern":"Circuit host not initialized\\.","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"critical","filePath":"src/Components/Web.JS/src/Platform/Circuits/CircuitManager.ts","lineNumber":166,"sourceCode":"    connection.on('JS.AttachComponent', (componentId, selector) => attachRootComponentToLogicalElement(WebRendererId.Server, this.resolveElement(selector), componentId, false));\n    connection.on('JS.BeginInvokeJS', (asyncHandle: number, ...rest: unknown[]) => {\n      if (asyncHandle !== 0) {\n        this.changeActivity(1);\n      }\n      (this._dispatcher.beginInvokeJSFromDotNet as (...a: unknown[]) => unknown)\n        .call(this._dispatcher, asyncHandle, ...rest);\n    });\n    connection.on('JS.EndInvokeDotNet', (asyncCallId: string, success: boolean, resultJsonOrExceptionMessage: string) => {\n      if (asyncCallId) {\n        this.changeActivity(-1);\n      }\n      this._dispatcher.endInvokeDotNetFromJS(asyncCallId, success, resultJsonOrExceptionMessage);\n    });\n    connection.on('JS.ReceiveByteArray', this._dispatcher.receiveByteArray.bind(this._dispatcher));\n\n    connection.on('JS.SavePersistedState', (circuitId: string, components: string, applicationState: string) => {\n      if (!this._circuitId) {\n        throw new Error('Circuit host not initialized.');\n      }\n      if (circuitId !== this._circuitId) {\n        throw new Error(`Received persisted state for circuit ID '${circuitId}', but the current circuit ID is '${this._circuitId}'.`);\n      }\n      this._persistedCircuitState = { components, applicationState };\n      return true;\n    });\n\n    connection.on('JS.BeginTransmitStream', (streamId: number) => {\n      const readableStream = new ReadableStream({\n        start: (controller) => {\n          this.changeActivity(1);\n          connection.stream('SendDotNetStreamToJS', streamId).subscribe({\n            next: (chunk: Uint8Array) => controller.enqueue(chunk),\n            complete: () => { controller.close(); this.changeActivity(-1); },\n            error: (err) => { controller.error(err); this.changeActivity(-1); },\n          });\n        },","sourceCodeStart":148,"sourceCodeEnd":184,"githubUrl":"https://github.com/dotnet/aspnetcore/blob/294cab2f9b2e03af6b953820c7ab497c3c8b7ad9/src/Components/Web.JS/src/Platform/Circuits/CircuitManager.ts#L148-L184","documentation":"Thrown inside the SignalR 'JS.SavePersistedState' handler when the server sends persisted component/application state before _circuitId has been assigned. _circuitId is set only after a successful StartCircuit invoke, so receiving SavePersistedState before that point means the circuit handshake ran out of order or against an uninitialized circuit.","triggerScenarios":"Server-initiated persisted-state push arriving during/after a connection race, a reconnect/restart sequence where the prior circuit was not fully established, or a server version mismatch sending SavePersistedState earlier than the client expects.","commonSituations":"Circuit resumption (pause/resume) flows under poor connectivity; running a newer server against an older blazor.*.js (or vice versa); custom reconnection handlers that interfere with circuit startup ordering.","solutions":["Ensure the blazor.web.js / blazor.server.js version exactly matches the ASP.NET Core server version shipping the app.","Let the framework own circuit lifecycle; do not manually pause/resume or send state out of band.","On persistent errors, force a full page reload to re-establish a clean circuit handshake."],"exampleFix":null,"handlingStrategy":"validation","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":["Keep blazor.*.js version aligned with the server framework version.","Let the framework own circuit startup ordering; do not inject state out of band.","On persistent startup errors, force a full page reload."],"tags":["blazor-server","circuit","signalr","state-persistence"],"analyzedSha":"294cab2f9b2e03af6b953820c7ab497c3c8b7ad9","analyzedAt":"2026-08-06T20:08:02.189Z","schemaVersion":2},"datasetVersion":"2026-08-06T23:17:07.152Z"}