{"record":{"id":"0418c997ce5c9f63","repo":"microsoft/aspire","slug":"the-endpoint-ea-name-for-resource-modelresourcename","errorCode":null,"errorMessage":"The endpoint '{ea.Name}' for resource '{modelResourceName}' requested a proxy (IsProxied is true). Non-container resources cannot be proxied when both TargetPort and Port are specified with the same value.","messagePattern":"The endpoint '(.+?)' for resource '(.+?)' requested a proxy \\(IsProxied is true\\)\\. Non-container resources cannot be proxied when both TargetPort and Port are specified with the same value\\.","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"src/Aspire.Hosting/Dcp/DcpModelUtilities.cs","lineNumber":80,"sourceCode":"            var ea = sp.EndpointAnnotation;\n            ValidateEndpointPorts(modelResource, ea);\n\n            if (!modelResource.IsContainer())\n            {\n                if (!ea.IsProxied)\n                {\n                    if (HasMultipleReplicas(appResource.DcpResource))\n                    {\n                        throw new InvalidOperationException($\"Resource '{modelResourceName}' uses multiple replicas and a proxy-less endpoint '{ea.Name}'. These features do not work together.\");\n                    }\n                }\n                else\n                {\n                    Debug.Assert(ea.IsProxied);\n\n                    if (ea.TargetPort is int && ea.Port is int && ea.TargetPort == ea.Port)\n                    {\n                        throw new InvalidOperationException(\n                            $\"The endpoint '{ea.Name}' for resource '{modelResourceName}' requested a proxy ({nameof(ea.IsProxied)} is true). Non-container resources cannot be proxied when both {nameof(ea.TargetPort)} and {nameof(ea.Port)} are specified with the same value.\");\n                    }\n\n                    if (HasMultipleReplicas(appResource.DcpResource) && ea.TargetPort is int)\n                    {\n                        throw new InvalidOperationException(\n                            $\"Resource '{modelResourceName}' can have multiple replicas, and it uses endpoint '{ea.Name}' that has {nameof(ea.TargetPort)} property set. Each replica must have a unique port; setting {nameof(ea.TargetPort)} is not allowed.\");\n                    }\n                }\n            }\n\n            var spAnn = new ServiceProducerAnnotation(sp.Service.Metadata.Name);\n            (spAnn.Address, _) = NormalizeTargetHost(ea.TargetHost);\n            spAnn.Port = ea.TargetPort;\n            appResource.DcpResource.AnnotateAsObjectList(CustomResource.ServiceProducerAnnotation, spAnn);\n            appResource.ServicesProduced.Add(sp);\n        }\n","sourceCodeStart":62,"sourceCodeEnd":98,"githubUrl":"https://github.com/microsoft/aspire/blob/25830f84bd145686607ad00c057b3f84e2e51d43/src/Aspire.Hosting/Dcp/DcpModelUtilities.cs#L62-L98","documentation":"For a non-container resource with a proxied endpoint, Aspire requires that the port be free to be allocated; specifying both an explicit TargetPort and an explicit Port with the same value defeats the proxy's ability to choose a port and would collide across replicas. It throws when both are set and equal.","triggerScenarios":"AddProject/AddExecutable resource with WithEndpoint(name, port: 8080, targetPort: 8080) (or WithHttpEndpoint equivalents) while IsProxied remains true, evaluated in AddServicesProducedInfo.","commonSituations":"Porting an app from direct Kestrel/port config where the listen port equals the public port; copy-pasting endpoint config from container setups where fixed port:targetPort pairs are normal.","solutions":["Remove the explicit port (public Port) argument and let the proxy allocate one: WithEndpoint(name: \"http\", targetPort: 8080).","If the process must listen on a fixed port with no proxy, set isProxied: false and specify only targetPort.","If the fixed public port is required, make the endpoint unproxied and ensure replicas stay at 1."],"exampleFix":"// before\n.WithEndpoint(\"http\", e => { e.Port = 8080; e.TargetPort = 8080; e.IsProxied = true; })\n// after\n.WithEndpoint(\"http\", e => { e.TargetPort = 8080; e.IsProxied = true; })","handlingStrategy":"validation","validationCode":"var proxiedFixedPort = endpoints.Where(e => e.IsProxied)\n    .Any(e => e.TargetPort is int t && e.Port is int p && t == p);\nif (proxiedFixedPort) throw new InvalidOperationException(\"Proxied endpoints must not pin both Port and TargetPort to the same value.\");","typeGuard":null,"tryCatchPattern":"try\n{\n    builder.Build().Run();\n}\ncatch (InvalidOperationException ex) when (ex.Message.Contains(\"cannot be proxied when both\"))\n{\n    // drop the explicit Port or switch to isProxied:false\n}","preventionTips":["For proxied endpoints, only ever set targetPort; let the proxy choose the public port.","Don't copy container-style port:port pairs onto project/executable endpoints.","Review WithEndpoint calls after migrating from direct Kestrel port configuration."],"tags":["aspire","dcp","endpoint","proxy","port"],"backgroundTag":"conflicting-config-options","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"}