microsoft/aspire · error · ArgumentOutOfRangeException

Connector Namespace resource names must contain between 2…

Error message

Connector Namespace resource names must contain between 2 and 64 characters.

What it means

Aspire validates that Connector Namespace resource names are between 2 and 64 characters before creating the underlying Azure resource. Azure rejects names outside this range, so AddConnection, WithAccessPolicy, WithIdentityAccessPolicy, and AddMcpServerConfig throw an ArgumentOutOfRangeException up front with the offending value.

Solutions

  1. Shorten the name to at most 64 characters
  2. Lengthen the name to at least 2 characters
  3. Compute names from constants and assert length before calling the API

Example fix

// before
builder.AddAzureConnectorNamespace("ns").AddConnection("x", ...);
// after
builder.AddAzureConnectorNamespace("ns").AddConnection("sql-conn", ...);
Defensive patterns

Strategy: validation

Validate before calling

if (string.IsNullOrWhiteSpace(name) || name.Length is < 2 or > 64)
    throw new ArgumentOutOfRangeException(nameof(name), name, "Name must be 2-64 characters.");

Try / catch

try { builder.AddConnection(name, ...); }
catch (ArgumentOutOfRangeException ex) when (ex.ParamName == "name") { log.LogError(ex, "Invalid name length"); }

Prevention

When it happens

Trigger: Calling any of AddConnection/WithAccessPolicy/WithIdentityAccessPolicy/AddMcpServerConfig on an Azure Connector Namespace with a name argument whose string length is 1 character or 65+ characters.

Common situations: Generating names programmatically from GUIDs or concatenations that exceed 64 chars; passing a single-character short name like 'a'; truncation logic producing a 1-char string.

Understand the failure class

Background: "value must be between 0 and 1" / "out of range" / "must not be negative" errors: fixing range-validation failures across open-source libraries — this error's family across 42 libraries.

Related errors


AI-assisted analysis of microsoft/aspire@25830f84bd (2026-09-16). Data as JSON: /api/errors/e766a978d4ad8702. Report an issue: GitHub.

Appendix: source

Thrown at src/Aspire.Hosting.Azure.ConnectorNamespace/AzureConnectorNamespaceExtensions.cs:755

        ArgumentException.ThrowIfNullOrWhiteSpace(objectId, objectIdParamName);
        ArgumentException.ThrowIfNullOrWhiteSpace(tenantId, tenantIdParamName);
        if (!Guid.TryParse(objectId, out _))
        {
            throw new ArgumentException($"The {policyDescription} object ID must be a valid GUID.", paramName);
        }

        if (!Guid.TryParse(tenantId, out _))
        {
            throw new ArgumentException($"The {policyDescription} tenant ID must be a valid GUID.", paramName);
        }
    }

    private static void ValidateConnectorResourceName(string name, string paramName)
    {
        ArgumentException.ThrowIfNullOrWhiteSpace(name, paramName);
        if (name.Length is < 2 or > 64)
        {
            throw new ArgumentOutOfRangeException(
                paramName,
                name,
                "Connector Namespace resource names must contain between 2 and 64 characters.");
        }

        if (name.Any(static character =>
            !char.IsAsciiLetterOrDigit(character) &&
            character is not '-' and not '_'))
        {
            throw new ArgumentException(
                "Connector Namespace resource names can contain only ASCII letters, numbers, hyphens, and underscores.",
                paramName);
        }
    }

}

View on GitHub (pinned to 25830f84bd)