{"record":{"id":"2c7a9a5a768611af","repo":"microsoft/aspire","slug":"the-endpoint-endpoint-name-for-resource-modelresourcename-is","errorCode":null,"errorMessage":"The endpoint '{endpoint.Name}' for resource '{modelResourceName}' is not using a proxy, and it has a value of Port property that is different from the value of TargetPort property. For proxy-less endpoints they must match.","messagePattern":"The endpoint '(.+?)' for resource '(.+?)' is not using a proxy, and it has a value of Port property that is different from the value of TargetPort property\\. For proxy-less endpoints they must match\\.","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"src/Aspire.Hosting/Dcp/DcpModelUtilities.cs","lineNumber":44,"sourceCode":"        return start == false &&\n            modelResource.TryGetLastAnnotation<ExplicitStartupAnnotation>(out _) &&\n            modelResource.GetLifetimeType() != Lifetime.Persistent;\n    }\n\n    internal static void ValidateEndpointPorts(IResource modelResource, EndpointAnnotation endpoint)\n    {\n        var modelResourceName = modelResource.Name ?? \"(unknown)\";\n\n        if (modelResource.IsContainer())\n        {\n            if (EndpointAnnotation.NormalizePort(endpoint.TargetPort) is null)\n            {\n                throw new InvalidOperationException($\"The endpoint '{endpoint.Name}' for container resource '{modelResourceName}' must specify the {nameof(EndpointAnnotation.TargetPort)} value\");\n            }\n        }\n        else if (!endpoint.IsProxied && endpoint.Port is int && endpoint.Port != endpoint.TargetPort)\n        {\n            throw new InvalidOperationException($\"The endpoint '{endpoint.Name}' for resource '{modelResourceName}' is not using a proxy, and it has a value of {nameof(EndpointAnnotation.Port)} property that is different from the value of {nameof(EndpointAnnotation.TargetPort)} property. For proxy-less endpoints they must match.\");\n        }\n    }\n\n    /// <summary>\n    /// Examines the Aspire resource annotations and adds equivalent ServiceProducerAnnotations to the corresponding DCP resource.\n    /// </summary>\n    internal static void AddServicesProducedInfo<TDcpResource>(\n        RenderedModelResource<TDcpResource> appResource,\n        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;","sourceCodeStart":26,"sourceCodeEnd":62,"githubUrl":"https://github.com/microsoft/aspire/blob/25830f84bd145686607ad00c057b3f84e2e51d43/src/Aspire.Hosting/Dcp/DcpModelUtilities.cs#L26-L62","documentation":"For proxy-less (unproxied) endpoints, DcpModelUtilities requires the Port (the publicly exposed port) and TargetPort (the port the process listens on) to be identical, because without the DCP proxy there is no port forwarding between them. When they differ, endpoint allocation cannot produce a coherent mapping and it throws InvalidOperationException.","triggerScenarios":"Calling WithEndpoint with an explicit port and targetPort that differ while passing isProxied: false (or using a resource where proxying is disabled), then running the AppHost — e.g. WithEndpoint(port: 8080, targetPort: 5000, isProxied: false).","commonSituations":"Migrating from proxied to proxy-less endpoints (e.g. for gRPC/HTTPS direct binding) without consolidating port values; setting Port for a 'nice' external port while the app still listens on a different port; forgetting that proxy-less mode removes the port-mapping layer entirely.","solutions":["Make port and targetPort the same value on every isProxied: false endpoint.","If you need different external/internal ports, keep the endpoint proxied (default) so the DCP proxy maps them.","Update the app to listen on the exact port you expose and remove the mismatched Port override.","For containers with proxy-less endpoints, also ensure the container internally listens on that same port."],"exampleFix":"// before: mismatched ports on proxy-less endpoint\n.WithEndpoint(port: 8080, targetPort: 5000, isProxied: false)\n// after: equal ports for proxy-less endpoints\n.WithEndpoint(port: 8080, targetPort: 8080, isProxied: false)","handlingStrategy":"validation","validationCode":"static void EnsureProxylessPortsMatch(EndpointAnnotation e)\n{\n    if (!e.IsProxied && e.Port is int p && p != e.TargetPort)\n        throw new InvalidOperationException($\"Proxy-less endpoint '{e.Name}' requires Port == TargetPort.\");\n}","typeGuard":"static bool IsProxylessConfigValid(EndpointAnnotation e) =>\n    e.IsProxied || e.Port is not int p || p == e.TargetPort;","tryCatchPattern":"try { await builder.Build().RunAsync(); }\ncatch (InvalidOperationException ex) when (ex.Message.Contains(\"For proxy-less endpoints they must match\"))\n{\n    // equalize port and targetPort or re-enable the proxy\n}","preventionTips":["Keep port == targetPort for every isProxied: false endpoint","Use the proxy (default) when you need different external/internal ports","Configure the app to listen exactly on the exposed port in proxy-less mode"],"tags":["endpoints","proxy","configuration","validation"],"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"}