{"record":{"id":"faedb5a752de421c","repo":"microsoft/aspire","slug":"not-connected-to-auxiliary-backchannel","errorCode":null,"errorMessage":"Not connected to auxiliary backchannel.","messagePattern":"Not connected to auxiliary backchannel\\.","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"src/Aspire.Cli/Backchannel/AppHostAuxiliaryBackchannel.cs","lineNumber":119,"sourceCode":"    /// <inheritdoc />\n    public bool SupportsResourceSnapshotVersionsV1 => _capabilities.Contains(AuxiliaryBackchannelCapabilities.ResourceSnapshotVersions_V1);\n\n    /// <summary>\n    /// Gets the JSON-RPC proxy for communicating with the AppHost.\n    /// </summary>\n    internal JsonRpc? Rpc => _rpc;\n\n    /// <summary>\n    /// Ensures the connection is valid and returns the RPC proxy.\n    /// </summary>\n    /// <exception cref=\"ObjectDisposedException\">Thrown if the object has been disposed.</exception>\n    /// <exception cref=\"InvalidOperationException\">Thrown if not connected to the backchannel.</exception>\n    private JsonRpc EnsureConnected()\n    {\n        ObjectDisposedException.ThrowIf(_disposed, this);\n        if (_rpc is null)\n        {\n            throw new InvalidOperationException(\"Not connected to auxiliary backchannel.\");\n        }\n        return _rpc;\n    }\n\n    /// <summary>\n    /// Creates and connects a new auxiliary backchannel to the specified socket.\n    /// </summary>\n    /// <param name=\"appHostSocket\">The AppHost socket to connect to.</param>\n    /// <param name=\"logger\">Logger for diagnostic messages.</param>\n    /// <param name=\"profilingTelemetry\">Profiling service.</param>\n    /// <param name=\"cancellationToken\">Cancellation token.</param>\n    /// <returns>A connected AppHostAuxiliaryBackchannel instance.</returns>\n    public static Task<AppHostAuxiliaryBackchannel> ConnectAsync(\n        IAppHostSocket appHostSocket,\n        ILogger logger,\n        ProfilingTelemetry profilingTelemetry,\n        CancellationToken cancellationToken = default)\n    {","sourceCodeStart":101,"sourceCodeEnd":137,"githubUrl":"https://github.com/microsoft/aspire/blob/25830f84bd145686607ad00c057b3f84e2e51d43/src/Aspire.Cli/Backchannel/AppHostAuxiliaryBackchannel.cs#L101-L137","documentation":"AppHostAuxiliaryBackchannel.EnsureConnected returns the active JsonRpc instance but throws if the backchannel has never connected or was disposed. Callers of RPC methods must have completed ConnectAsync first. This is a state-check guard: you are invoking a backchannel RPC without an established connection.","triggerScenarios":"Thrown when any RPC operation calls EnsureConnected while the private _rpc field is null — i.e. methods are invoked before ConnectAsync completed, after a failed connect, or after the instance was created but never connected.","commonSituations":"Calling auxiliary backchannel APIs before awaiting ConnectAsync; connection setup failed earlier (socket absent, AppHost not ready) and the error surfaces later on first RPC; constructing the backchannel manually in tests/tools without connecting it.","solutions":["Call and await ConnectAsync (with the correct socket path) before issuing any RPC calls.","Check that the AppHost process is running and its auxiliary backchannel socket exists before connecting.","Guard call sites so RPCs are only attempted after a successful connect (check the connection task/state).","Recreate the backchannel instance and reconnect if a previous connection attempt failed."],"exampleFix":"// before\nvar backchannel = new AppHostAuxiliaryBackchannel();\nvar result = await backchannel.RequestSomethingAsync(); // throws\n// after\nvar backchannel = new AppHostAuxiliaryBackchannel();\nawait backchannel.ConnectAsync(socketPath, ...);\nvar result = await backchannel.RequestSomethingAsync();","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try\n{\n    await backchannel.RequestAsync(...);\n}\ncatch (InvalidOperationException ex) when (ex.Message == \"Not connected to auxiliary backchannel.\")\n{\n    await backchannel.ConnectAsync(socketPath, ...); // connect once, then retry\n}","preventionTips":["Always await ConnectAsync before invoking any auxiliary backchannel RPC.","Treat connect failures immediately rather than deferring them to the first RPC call.","In tests/tools, construct-and-connect in one setup helper to avoid unconnected instances."],"tags":["backchannel","rpc","connection-state","cli"],"backgroundTag":"invalid-state-transition","analyzedSha":"25830f84bd145686607ad00c057b3f84e2e51d43","analyzedAt":"2026-09-16T11:10:06.193Z","contentChangedAt":"2026-09-16T11:10:06.193Z","schemaVersion":2},"datasetVersion":"2026-09-21T04:17:39.646Z"}