microsoft/aspire · error · NotSupportedException

Container port is required for all endpoints

Error message

Container port is required for all endpoints

What it means

Aspire's Azure Container Apps publishing requires every endpoint on a container resource to specify which container port it targets. When grouping endpoints by target port, an endpoint group with a null port means the endpoint has no usable container port, so publishing cannot generate the Container App's port configuration and this NotSupportedException is thrown.

Solutions

  1. Set an explicit container port on the endpoint, e.g. .WithHttpEndpoint(port: 8080)
  2. For project resources, ensure the project exposes the port or set the endpoint's target port explicitly
  3. Check the resource's Endpoints annotations for one with a null Port and correct it before publish
  4. If the endpoint is not needed for the container app, remove it

Example fix

// before
var cache = builder.AddRedis("cache").WithEndpoint("tcp", e => e.Port = 6379); // endpoint with no container port
// after
var cache = builder.AddRedis("cache").WithEndpoint("tcp", e => { e.Port = 6379; e.TargetPort = 6379; });
Defensive patterns

Strategy: validation

Validate before calling

foreach (var ep in resource.Annotations.OfType<EndpointAnnotation>())
{
    if (ep.TargetPort is null)
        throw new InvalidOperationException($"Endpoint '{ep.Name}' on '{resource.Name}' needs a container port before publishing to Container Apps.");
}

Try / catch

try { await publisher.PublishAsync(model); }
catch (NotSupportedException ex) when (ex.Message.Contains("Container port is required")) { /* surface: add target port to endpoints */ }

Prevention

When it happens

Trigger: Calling WithEndpoint/WithHttpEndpoint/WithHttpsEndpoint (or ProjectResource endpoints) on a resource published to Azure Container Apps where the endpoint's target port (ContainerPort) is null — e.g. endpoints created without WithEndpoint(port) target port or endpoint annotation lacking a port.

Common situations: Developers add an endpoint like .WithHttpEndpoint() without specifying the port and rely on defaults that don't exist at publish time; custom resources with endpoints but no explicit container port; changes in endpoint resolution leaving TargetPort unset.

Understand the failure class

Background: "missing required argument" and "the following required arguments were not provided": what required-argument errors mean and how to fix them — this error's family across 20 libraries.

Related errors


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

Appendix: source

Thrown at src/Aspire.Hosting.Azure.AppContainers/ContainerAppContext.cs:255

                var upgradedEndpoints = httpIngress.ResolvedEndpoints
                    .Where(r => r.Endpoint.UriScheme is "http")
                    .Select(r => r.Endpoint.Name)
                    .ToArray();

                _containerAppEnvironmentContext.RecordHttpsUpgrade(Resource.Name, upgradedEndpoints);
            }
        }

        if (endpointsByTargetPort.Count > 5)
        {
            _containerAppEnvironmentContext.Logger.LogWarning("More than 5 additional ports are not supported. See https://learn.microsoft.com/azure/container-apps/ingress-overview#tcp for more details.");
        }

        foreach (var g in endpointsByTargetPort)
        {
            if (g.Port is null)
            {
                throw new NotSupportedException("Container port is required for all endpoints");
            }

            _additionalPorts.Add(g.Port.Value);

            foreach (var resolved in g.ResolvedEndpoints)
            {
                var endpoint = resolved.Endpoint;
                _endpointMapping[endpoint.Name] = new(endpoint.UriScheme, NormalizedContainerAppName, resolved.ExposedPort.Value ?? g.Port.Value, g.Port.Value, false, g.External, endpoint.TlsEnabled);
            }
        }
    }

    private void AddIngress(ContainerAppConfiguration config)
    {
        if (_httpIngress is null && _additionalPorts.Count == 0)
        {
            return;
        }

View on GitHub (pinned to 25830f84bd)