{"record":{"id":"e9fad7a20dae15eb","repo":"microsoft/aspire","slug":"service-svc-metadata-name-needs-to-specify-a-port-for","errorCode":null,"errorMessage":"Service '{svc.Metadata.Name}' needs to specify a port for endpoint '{sp.EndpointAnnotation.Name}' since it isn't using a proxy.","messagePattern":"Service '(.+?)' needs to specify a port for endpoint '(.+?)' since it isn't using a proxy\\.","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"src/Aspire.Hosting/Dcp/DcpModelUtilities.cs","lineNumber":191,"sourceCode":"        {\n            if (allowPending)\n            {\n                return false;\n            }\n\n            // This should never happen; if it does, we have a bug without a workaround for the user.\n            // We should have waited for the service to have a complete address before getting here.\n            throw new InvalidDataException($\"Service {svc.Metadata.Name} should have valid address at this point\");\n        }\n\n        if (!sp.EndpointAnnotation.IsProxied && allocatedPort is null)\n        {\n            if (allowPending)\n            {\n                return false;\n            }\n\n            throw new InvalidOperationException($\"Service '{svc.Metadata.Name}' needs to specify a port for endpoint '{sp.EndpointAnnotation.Name}' since it isn't using a proxy.\");\n        }\n\n        if (allocatedPort is null || string.IsNullOrEmpty(svc.AllocatedAddress))\n        {\n            if (allowPending)\n            {\n                return false;\n            }\n\n            throw new InvalidDataException($\"Service {svc.Metadata.Name} should have valid address at this point\");\n        }\n\n        var (targetHost, bindingMode) = NormalizeTargetHost(sp.EndpointAnnotation.TargetHost);\n\n        sp.EndpointAnnotation.AllocatedEndpoint = new AllocatedEndpoint(\n            sp.EndpointAnnotation,\n            targetHost,\n            allocatedPort.Value,","sourceCodeStart":173,"sourceCodeEnd":209,"githubUrl":"https://github.com/microsoft/aspire/blob/25830f84bd145686607ad00c057b3f84e2e51d43/src/Aspire.Hosting/Dcp/DcpModelUtilities.cs#L173-L209","documentation":"A proxy-less (IsProxied == false) endpoint must have its port specified somewhere — via targetPort on the endpoint or the process listening port — because DCP will not allocate/choose one. When no port is known and the call isn't allowing pending endpoints, Aspire throws.","triggerScenarios":"Non-container resource with WithEndpoint(..., isProxied: false) but no targetPort and no resolvable listening port (e.g. project doesn't expose its Kestrel port), when TryAddWorkloadAllocatedEndpoints/ApplyServiceAddressToEndpoint runs with allowPending=false.","commonSituations":"Switching an endpoint to isProxied:false to skip the proxy while forgetting to pin the port; executables that listen on a random port and never publish it; launchSettings changes removing the port.","solutions":["Specify the port explicitly: WithEndpoint(name: \"http\", targetPort: 5080, isProxied: false).","Make the application listen on that fixed port (Kestrel config/launchSettings) so the endpoint annotation can bind it.","Re-enable the proxy (isProxied: true) if a dynamic port is acceptable."],"exampleFix":"// before\n.WithEndpoint(\"http\", e => e.IsProxied = false)\n// after\n.WithEndpoint(\"http\", e => { e.IsProxied = false; e.TargetPort = 5080; })","handlingStrategy":"validation","validationCode":"foreach (var ep in resource.Annotations.OfType<EndpointAnnotation>())\n{\n    if (!ep.IsProxied && ep.TargetPort is null && ep.Port is null)\n        throw new InvalidOperationException($\"{resource.Name}: unproxied endpoint '{ep.Name}' needs an explicit port.\");\n}","typeGuard":null,"tryCatchPattern":"try\n{\n    app.Run();\n}\ncatch (InvalidOperationException ex) when (ex.Message.Contains(\"needs to specify a port\"))\n{\n    // add targetPort to the unproxied endpoint or re-enable the proxy\n}","preventionTips":["Whenever setting isProxied:false, always pass an explicit targetPort in the same change.","Ensure the app actually listens on the pinned port (Kestrel/launchSettings alignment).","Only use proxy-less endpoints for processes with deterministic listening ports."],"tags":["aspire","dcp","endpoint","proxy","port"],"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"}