{"record":{"id":"ada967301f8b4026","repo":"microsoft/aspire","slug":"container-port-is-required-for-all-endpoints","errorCode":null,"errorMessage":"Container port is required for all endpoints","messagePattern":"Container port is required for all endpoints","errorType":"exception","errorClass":"NotSupportedException","httpStatus":null,"severity":"error","filePath":"src/Aspire.Hosting.Azure.AppContainers/ContainerAppContext.cs","lineNumber":255,"sourceCode":"                var upgradedEndpoints = httpIngress.ResolvedEndpoints\n                    .Where(r => r.Endpoint.UriScheme is \"http\")\n                    .Select(r => r.Endpoint.Name)\n                    .ToArray();\n\n                _containerAppEnvironmentContext.RecordHttpsUpgrade(Resource.Name, upgradedEndpoints);\n            }\n        }\n\n        if (endpointsByTargetPort.Count > 5)\n        {\n            _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.\");\n        }\n\n        foreach (var g in endpointsByTargetPort)\n        {\n            if (g.Port is null)\n            {\n                throw new NotSupportedException(\"Container port is required for all endpoints\");\n            }\n\n            _additionalPorts.Add(g.Port.Value);\n\n            foreach (var resolved in g.ResolvedEndpoints)\n            {\n                var endpoint = resolved.Endpoint;\n                _endpointMapping[endpoint.Name] = new(endpoint.UriScheme, NormalizedContainerAppName, resolved.ExposedPort.Value ?? g.Port.Value, g.Port.Value, false, g.External, endpoint.TlsEnabled);\n            }\n        }\n    }\n\n    private void AddIngress(ContainerAppConfiguration config)\n    {\n        if (_httpIngress is null && _additionalPorts.Count == 0)\n        {\n            return;\n        }","sourceCodeStart":237,"sourceCodeEnd":273,"githubUrl":"https://github.com/microsoft/aspire/blob/25830f84bd145686607ad00c057b3f84e2e51d43/src/Aspire.Hosting.Azure.AppContainers/ContainerAppContext.cs#L237-L273","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Set an explicit container port on the endpoint, e.g. .WithHttpEndpoint(port: 8080)","For project resources, ensure the project exposes the port or set the endpoint's target port explicitly","Check the resource's Endpoints annotations for one with a null Port and correct it before publish","If the endpoint is not needed for the container app, remove it"],"exampleFix":"// before\nvar cache = builder.AddRedis(\"cache\").WithEndpoint(\"tcp\", e => e.Port = 6379); // endpoint with no container port\n// after\nvar cache = builder.AddRedis(\"cache\").WithEndpoint(\"tcp\", e => { e.Port = 6379; e.TargetPort = 6379; });","handlingStrategy":"validation","validationCode":"foreach (var ep in resource.Annotations.OfType<EndpointAnnotation>())\n{\n    if (ep.TargetPort is null)\n        throw new InvalidOperationException($\"Endpoint '{ep.Name}' on '{resource.Name}' needs a container port before publishing to Container Apps.\");\n}","typeGuard":null,"tryCatchPattern":"try { await publisher.PublishAsync(model); }\ncatch (NotSupportedException ex) when (ex.Message.Contains(\"Container port is required\")) { /* surface: add target port to endpoints */ }","preventionTips":["Always pass an explicit port to WithHttpEndpoint/WithHttpsEndpoint for container-published resources","Review endpoint annotations before publish in a custom publish callback","Remember Aspire does not infer container ports for custom resources"],"tags":["azure","container-apps","endpoints","publish"],"backgroundTag":"missing-required-argument","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"}