{"record":{"id":"3ba528b384b3343b","repo":"SignalR/SignalR","slug":"the-persistentconnection-is-not-initialized","errorCode":null,"errorMessage":"The PersistentConnection is not initialized.","messagePattern":"The PersistentConnection is not initialized\\.","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.AspNet.SignalR.Core/PersistentConnection.cs","lineNumber":200,"sourceCode":"        /// Handles all requests for <see cref=\"PersistentConnection\"/>s.\n        /// </summary>\n        /// <param name=\"context\">The <see cref=\"HostContext\"/> for the current request.</param>\n        /// <returns>A <see cref=\"Task\"/> that completes when the <see cref=\"PersistentConnection\"/> pipeline is complete.</returns>\n        /// <exception cref=\"T:System.InvalidOperationException\">\n        /// Thrown if connection wasn't initialized.\n        /// Thrown if the transport wasn't specified.\n        /// Thrown if the connection id wasn't specified.\n        /// </exception>\n        public virtual Task ProcessRequest(HostContext context)\n        {\n            if (context == null)\n            {\n                throw new ArgumentNullException(\"context\");\n            }\n\n            if (!_initialized)\n            {\n                throw new InvalidOperationException(String.Format(CultureInfo.CurrentCulture, Resources.Error_ConnectionNotInitialized));\n            }\n\n            if (IsNegotiationRequest(context.Request))\n            {\n                return ProcessNegotiationRequest(context);\n            }\n            else if (IsPingRequest(context.Request))\n            {\n                return ProcessPingRequest(context);\n            }\n\n            Transport = GetTransport(context);\n\n            if (Transport == null)\n            {\n                return FailResponse(context.Response, String.Format(CultureInfo.CurrentCulture, Resources.Error_ProtocolErrorUnknownTransport));\n            }\n","sourceCodeStart":182,"sourceCodeEnd":218,"githubUrl":"https://github.com/SignalR/SignalR/blob/693053b89a9e1f5ce819e3233ed159a6409de22b/src/Microsoft.AspNet.SignalR.Core/PersistentConnection.cs#L182-L218","documentation":"Thrown by PersistentConnection.ProcessRequest when the _initialized flag is false. PersistentConnection instances must be initialized (via the Initialize method, which sets up the dependency resolver, configuration, and group manager) before they can process requests. This error means the connection was registered with the OWIN pipeline but Initialize was never called — typically a hosting or wiring problem, not a client issue.","triggerScenarios":"Calling ProcessRequest on a PersistentConnection before Initialize has been invoked. This happens when the connection is not properly registered through the standard SignalR OWIN pipeline (MapSignalR), or when a custom host constructs a PersistentConnection and dispatches requests manually without calling Initialize.","commonSituations":"A custom OWIN host that instantiates PersistentConnection directly instead of using MapSignalR; a unit test that calls ProcessRequest without setting up the connection; a misconfigured routing setup; using an older hosting pattern that bypasses initialization.","solutions":["Register the PersistentConnection through the standard pipeline: app.MapSignalR<MyConnection>(\"/path\").","If hosting manually, ensure Initialize(configuration, resolver, hostContext, ...) is called before ProcessRequest.","Do not instantiate PersistentConnection directly in custom middleware — let SignalR's infrastructure manage its lifecycle.","Check that the OWIN startup class is correctly configured and invoked."],"exampleFix":"// before — manual instantiation without init\nvar conn = new MyPersistentConnection();\nconn.ProcessRequest(hostContext); // throws\n\n// after — proper OWIN registration\napp.MapSignalR<MyPersistentConnection>(\"/myconnection\");\n\n// or if manual, call Initialize first\nvar conn = new MyPersistentConnection();\nconn.Initialize(configuration, resolver, hostContext, \"groupName\",\n                userIdProvider, ...);\nconn.ProcessRequest(hostContext);","handlingStrategy":"validation","validationCode":"// Ensure the connection is initialized before processing\n// Best approach: register through the standard pipeline\napp.MapSignalR<MyPersistentConnection>(\"/echo\");\n\n// If manual initialization is required:\nconnection.Initialize(configuration, resolver, hostContext,\n    DefaultSignalRaw, userIdProvider, ...);","typeGuard":null,"tryCatchPattern":"try {\n    await connection.ProcessRequest(hostContext);\n} catch (InvalidOperationException ex) when (ex.Message.Contains(\"not initialized\")) {\n    logger.Error(\"PersistentConnection not initialized — use MapSignalR or call Initialize first\", ex);\n    throw;\n}","preventionTips":["Register PersistentConnections via app.MapSignalR<T>(\"/path\") so the framework handles initialization.","Do not instantiate and call ProcessRequest manually without Initialize.","Verify the OWIN startup class is properly configured and invoked at app start."],"tags":["persistent-connection","lifecycle","signalr","startup","owin"],"backgroundTag":null,"analyzedSha":"693053b89a9e1f5ce819e3233ed159a6409de22b","analyzedAt":"2026-08-13T22:23:59.793Z","schemaVersion":2},"datasetVersion":"2026-08-14T00:17:13.853Z"}