{"record":{"id":"0b5e584e632a3275","repo":"microsoft/aspire","slug":"resource-modelresourcename-uses-multiple-replicas-and-a","errorCode":null,"errorMessage":"Resource '{modelResourceName}' uses multiple replicas and a proxy-less endpoint '{ea.Name}'. These features do not work together.","messagePattern":"Resource '(.+?)' uses multiple replicas and a proxy-less endpoint '(.+?)'\\. These features do not work together\\.","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"src/Aspire.Hosting/Dcp/DcpModelUtilities.cs","lineNumber":71,"sourceCode":"        IEnumerable<IAppResource> appResources)\n        where TDcpResource : CustomResource, IKubernetesStaticMetadata\n    {\n        var modelResource = appResource.ModelResource;\n        var modelResourceName = modelResource.Name ?? \"(unknown)\";\n\n        var servicesProduced = appResources.OfType<ServiceWithModelResource>().Where(r => r.ModelResource == modelResource);\n        foreach (var sp in servicesProduced)\n        {\n            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                }","sourceCodeStart":53,"sourceCodeEnd":89,"githubUrl":"https://github.com/microsoft/aspire/blob/25830f84bd145686607ad00c057b3f84e2e51d43/src/Aspire.Hosting/Dcp/DcpModelUtilities.cs#L53-L89","documentation":"Aspire rejects application-model resources that both run multiple replicas (instance count > 1) and expose a proxy-less endpoint (IsProxied = false). With no DCP proxy in front, each replica would need its own port, so the single endpoint cannot be surfaced coherently. The library throws at DCP model-generation time rather than failing confusingly at runtime.","triggerScenarios":"Calling WithReplicas(n>1) on a non-container resource (executable/project) that also has an endpoint created with WithEndpoint(..., isProxied: false) (or the endpoint defaults to unproxied), during AddServicesProducedInfo when DCP services are being built.","commonSituations":"Scaling out a console/executable project for throughput while having earlier switched the endpoint to isProxied:false to reduce latency; template or sample code where a teammate added replicas without noticing an existing unproxied endpoint annotation.","solutions":["Re-enable the proxy on the endpoint: WithEndpoint(name: ..., isProxied: true) so replicas can share one proxied endpoint.","Remove WithReplicas(n) (set replicas to 1) if you specifically need the proxy-less endpoint.","Move to a container resource, which supports proxy-less endpoints with replicas via port mapping semantics, if the proxy-less requirement is architectural."],"exampleFix":"// before\nvar svc = builder.AddProject<Projects.Worker>(\"worker\")\n    .WithEndpoint(\"http\", e => e.IsProxied = false)\n    .WithReplicas(3);\n// after\nvar svc = builder.AddProject<Projects.Worker>(\"worker\")\n    .WithEndpoint(\"http\", e => e.IsProxied = true)\n    .WithReplicas(3);","handlingStrategy":"validation","validationCode":"// Before running, assert endpoint/replica compatibility\nif (resource.GetReplicaCount() > 1)\n{\n    foreach (var ep in resource.Annotations.OfType<EndpointAnnotation>())\n        if (!ep.IsProxied)\n            throw new InvalidOperationException($\"{resource.Name}: unproxied endpoint '{ep.Name}' cannot be combined with replicas.\");\n}","typeGuard":null,"tryCatchPattern":"try\n{\n    appHost.Run();\n}\ncatch (InvalidOperationException ex) when (ex.Message.Contains(\"multiple replicas and a proxy-less endpoint\"))\n{\n    // fix endpoint/replica config before rerun\n}","preventionTips":["Keep non-container endpoints proxied unless you specifically need direct binding.","If you add WithReplicas, audit every WithEndpoint for isProxied:false.","Encode the constraint in a shared helper that configures endpoints for scaled projects."],"tags":["aspire","dcp","replicas","endpoint","proxy"],"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"}