SignalR/SignalR · error · InvalidOperationException
The PersistentConnection is not initialized.
Error message
The PersistentConnection is not initialized.
What it means
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.
Source
Thrown at src/Microsoft.AspNet.SignalR.Core/PersistentConnection.cs:200
/// Handles all requests for <see cref="PersistentConnection"/>s.
/// </summary>
/// <param name="context">The <see cref="HostContext"/> for the current request.</param>
/// <returns>A <see cref="Task"/> that completes when the <see cref="PersistentConnection"/> pipeline is complete.</returns>
/// <exception cref="T:System.InvalidOperationException">
/// Thrown if connection wasn't initialized.
/// Thrown if the transport wasn't specified.
/// Thrown if the connection id wasn't specified.
/// </exception>
public virtual Task ProcessRequest(HostContext context)
{
if (context == null)
{
throw new ArgumentNullException("context");
}
if (!_initialized)
{
throw new InvalidOperationException(String.Format(CultureInfo.CurrentCulture, Resources.Error_ConnectionNotInitialized));
}
if (IsNegotiationRequest(context.Request))
{
return ProcessNegotiationRequest(context);
}
else if (IsPingRequest(context.Request))
{
return ProcessPingRequest(context);
}
Transport = GetTransport(context);
if (Transport == null)
{
return FailResponse(context.Response, String.Format(CultureInfo.CurrentCulture, Resources.Error_ProtocolErrorUnknownTransport));
}
View on GitHub (pinned to 693053b89a)
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.
Example fix
// before — manual instantiation without init
var conn = new MyPersistentConnection();
conn.ProcessRequest(hostContext); // throws
// after — proper OWIN registration
app.MapSignalR<MyPersistentConnection>("/myconnection");
// or if manual, call Initialize first
var conn = new MyPersistentConnection();
conn.Initialize(configuration, resolver, hostContext, "groupName",
userIdProvider, ...);
conn.ProcessRequest(hostContext); Defensive patterns
Strategy: validation
Validate before calling
// Ensure the connection is initialized before processing
// Best approach: register through the standard pipeline
app.MapSignalR<MyPersistentConnection>("/echo");
// If manual initialization is required:
connection.Initialize(configuration, resolver, hostContext,
DefaultSignalRaw, userIdProvider, ...); Try / catch
try {
await connection.ProcessRequest(hostContext);
} catch (InvalidOperationException ex) when (ex.Message.Contains("not initialized")) {
logger.Error("PersistentConnection not initialized — use MapSignalR or call Initialize first", ex);
throw;
} Prevention
- 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.
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- A configuration object must be specified.
- A dependency resolver must be specified.
- SignalR: Connection must be started before data can be sent.
- SignalR: Connection has not been fully initialized. Use .sta
- The connection was stopped before it could be started.
AI-assisted analysis of SignalR/SignalR@693053b89a (2026-08-13).
Data as JSON: /api/errors/3ba528b384b3343b.
Report an issue: GitHub.