microsoft/aspire · error · InvalidOperationException
Connector connection
Error message
Connector connection '{connection.Resource.Name}' belongs to a different Connector Namespace. What it means
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.
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.
Example fix
// before
var nsA = azure.AddConnectorNamespace("ns-a");
var nsB = azure.AddConnectorNamespace("ns-b");
var conn = nsA.AddConnectorConnection("db");
nsB.AddMcpServerConfig("tools", options).WithConnector("db-conn", conn, o); // throws
// after
var ns = azure.AddConnectorNamespace("ns");
var conn = ns.AddConnectorConnection("db");
ns.AddMcpServerConfig("tools", options).WithConnector("db-conn", conn, o); Defensive patterns
Strategy: validation
Validate before calling
if (ReferenceEquals(mcp.Resource.Parent, connection.Resource.Parent))
{
mcp.WithConnector("db-conn", connection, connectorOptions);
} Try / catch
try
{
mcp.WithConnector("db-conn", connection, connectorOptions);
}
catch (InvalidOperationException ex) when (ex.Message.Contains("belongs to a different Connector Namespace"))
{
// create the connection on the same namespace as the MCP config
} Prevention
- 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.
When it happens
Trigger: 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.
Common situations: 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.
Understand the failure class
Background: "is not a compatible type" / "cannot merge" errors: when a value's type doesn't match what the library requires — this error's family across 65 libraries.
Related errors
- Existing MCP server configuration
- MCP server configuration
- Access policy ' ' is already registered on connector…
- Access policy resource
- At least one connector operation must be explicitly…
AI-assisted analysis of microsoft/aspire@25830f84bd (2026-09-16).
Data as JSON: /api/errors/173a89700a6a73a8.
Report an issue: GitHub.
Appendix: source
Thrown at src/Aspire.Hosting.Azure.ConnectorNamespace/AzureConnectorNamespaceExtensions.cs:596
this IResourceBuilder<AzureConnectorNamespaceMcpServerConfigResource> builder,
string connectorName,
IResourceBuilder<AzureConnectorNamespaceConnectionResource> connection,
AzureConnectorNamespaceMcpConnectorOptions options)
{
ArgumentNullException.ThrowIfNull(builder);
ArgumentException.ThrowIfNullOrWhiteSpace(connectorName);
ArgumentNullException.ThrowIfNull(connection);
ArgumentNullException.ThrowIfNull(options);
if (builder.Resource.IsExisting)
{
throw new InvalidOperationException(
$"Existing MCP server configuration '{builder.Resource.Name}' is read-only.");
}
if (!ReferenceEquals(builder.Resource.Parent, connection.Resource.Parent))
{
throw new InvalidOperationException(
$"Connector connection '{connection.Resource.Name}' belongs to a different Connector Namespace.");
}
if (builder.Resource.Connectors.Count > 0)
{
throw new InvalidOperationException(
$"MCP server configuration '{builder.Resource.Name}' already has a connector. " +
"The current Connector Namespace preview supports one connector per MCP server configuration.");
}
if (options.Operations is null || options.Operations.Length == 0)
{
throw new ArgumentException(
"At least one connector operation must be explicitly allow-listed.",
nameof(options));
}
var operationNames = new HashSet<string>(StringComparer.OrdinalIgnoreCase);View on GitHub (pinned to 25830f84bd)