{"record":{"id":"173a89700a6a73a8","repo":"microsoft/aspire","slug":"connector-connection-connection-resource-name-belongs-to-a","errorCode":null,"errorMessage":"Connector connection '{connection.Resource.Name}' belongs to a different Connector Namespace.","messagePattern":"Connector connection '(.+?)' belongs to a different Connector Namespace\\.","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"src/Aspire.Hosting.Azure.ConnectorNamespace/AzureConnectorNamespaceExtensions.cs","lineNumber":596,"sourceCode":"        this IResourceBuilder<AzureConnectorNamespaceMcpServerConfigResource> builder,\n        string connectorName,\n        IResourceBuilder<AzureConnectorNamespaceConnectionResource> connection,\n        AzureConnectorNamespaceMcpConnectorOptions options)\n    {\n        ArgumentNullException.ThrowIfNull(builder);\n        ArgumentException.ThrowIfNullOrWhiteSpace(connectorName);\n        ArgumentNullException.ThrowIfNull(connection);\n        ArgumentNullException.ThrowIfNull(options);\n\n        if (builder.Resource.IsExisting)\n        {\n            throw new InvalidOperationException(\n                $\"Existing MCP server configuration '{builder.Resource.Name}' is read-only.\");\n        }\n\n        if (!ReferenceEquals(builder.Resource.Parent, connection.Resource.Parent))\n        {\n            throw new InvalidOperationException(\n                $\"Connector connection '{connection.Resource.Name}' belongs to a different Connector Namespace.\");\n        }\n\n        if (builder.Resource.Connectors.Count > 0)\n        {\n            throw new InvalidOperationException(\n                $\"MCP server configuration '{builder.Resource.Name}' already has a connector. \" +\n                \"The current Connector Namespace preview supports one connector per MCP server configuration.\");\n        }\n\n        if (options.Operations is null || options.Operations.Length == 0)\n        {\n            throw new ArgumentException(\n                \"At least one connector operation must be explicitly allow-listed.\",\n                nameof(options));\n        }\n\n        var operationNames = new HashSet<string>(StringComparer.OrdinalIgnoreCase);","sourceCodeStart":578,"sourceCodeEnd":614,"githubUrl":"https://github.com/microsoft/aspire/blob/25830f84bd145686607ad00c057b3f84e2e51d43/src/Aspire.Hosting.Azure.ConnectorNamespace/AzureConnectorNamespaceExtensions.cs#L578-L614","documentation":"WithConnector requires the connector connection to belong to the same Connector Namespace as the MCP server configuration; cross-namespace wiring is not representable in the Azure Connector Namespace preview. The check uses reference equality of the Parent resources and throws when they differ.","triggerScenarios":"Calling mcpConfig.WithConnector(name, connection, options) where connection.Resource.Parent is a different AzureConnectorNamespaceResource instance than mcpConfig.Resource.Parent — e.g. two namespaces built in the same AppHost, each creating its own connections.","commonSituations":"Multiple Connector Namespaces defined (e.g. one per environment/team) and accidentally passing a connection from namespace A to an MCP config in namespace B; refactorings that renamed or re-created the namespace resource so the connection now hangs off a different instance.","solutions":["Pass a connection created on the same namespace: ns.AddConnectorConnection(...).WithConnector(...) on the MCP config from that same ns.","If cross-namespace sharing is intended, move the MCP server configuration (or the connection) into one shared namespace.","Verify that no duplicate AddConnectorNamespace calls created two namespace instances where one was expected."],"exampleFix":"// before\nvar nsA = azure.AddConnectorNamespace(\"ns-a\");\nvar nsB = azure.AddConnectorNamespace(\"ns-b\");\nvar conn = nsA.AddConnectorConnection(\"db\");\nnsB.AddMcpServerConfig(\"tools\", options).WithConnector(\"db-conn\", conn, o); // throws\n\n// after\nvar ns = azure.AddConnectorNamespace(\"ns\");\nvar conn = ns.AddConnectorConnection(\"db\");\nns.AddMcpServerConfig(\"tools\", options).WithConnector(\"db-conn\", conn, o);","handlingStrategy":"validation","validationCode":"if (ReferenceEquals(mcp.Resource.Parent, connection.Resource.Parent))\n{\n    mcp.WithConnector(\"db-conn\", connection, connectorOptions);\n}","typeGuard":null,"tryCatchPattern":"try\n{\n    mcp.WithConnector(\"db-conn\", connection, connectorOptions);\n}\ncatch (InvalidOperationException ex) when (ex.Message.Contains(\"belongs to a different Connector Namespace\"))\n{\n    // create the connection on the same namespace as the MCP config\n}","preventionTips":["Always create connections and MCP configs from the same namespace builder instance.","Avoid defining multiple AddConnectorNamespace resources unless you track ownership carefully.","Verify the connection variable's origin when namespaces were refactored or renamed."],"tags":["azure","aspire-hosting","connector","cross-namespace"],"backgroundTag":"incompatible-source-type","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"}