{"record":{"id":"48cbd9c5fa26ee32","repo":"microsoft/aspire","slug":"endpoint-resolvedendpoint-endpoint-name-on-resource-resource","errorCode":null,"errorMessage":"Endpoint '{resolvedEndpoint.Endpoint.Name}' on resource '{resource.TargetResource.Name}' does not have a target port. Configure a target port before deploying it to an Azure sandbox.","messagePattern":"Endpoint '(.+?)' on resource '(.+?)' does not have a target port\\. Configure a target port before deploying it to an Azure sandbox\\.","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"src/Aspire.Hosting.Azure.Sandboxes/AzureSandboxContainerDeployment.cs","lineNumber":1506,"sourceCode":"                continue;\n            }\n\n            if (resource.TargetResource is ProjectResource &&\n                string.Equals(resolvedEndpoint.Endpoint.UriScheme, Uri.UriSchemeHttps, StringComparison.OrdinalIgnoreCase) &&\n                !resolvedEndpoints.Any(candidate =>\n                    string.Equals(candidate.Endpoint.UriScheme, Uri.UriSchemeHttp, StringComparison.OrdinalIgnoreCase) &&\n                    candidate.TargetPort.Value == resolvedEndpoint.TargetPort.Value))\n            {\n                throw new NotSupportedException(\n                    $\"Endpoint '{resolvedEndpoint.Endpoint.Name}' on project resource '{resource.TargetResource.Name}' is exposed through Azure sandbox ingress, which terminates TLS and forwards plaintext HTTP. \" +\n                    \"Add an HTTP endpoint that shares this endpoint's target port.\");\n            }\n\n            var targetPort = ResolveSandboxTargetPort(resource.TargetResource, resolvedEndpoint);\n\n            if (targetPort is not int resolvedTargetPort)\n            {\n                throw new InvalidOperationException($\"Endpoint '{resolvedEndpoint.Endpoint.Name}' on resource '{resource.TargetResource.Name}' does not have a target port. Configure a target port before deploying it to an Azure sandbox.\");\n            }\n\n            var protocol = ResolveSandboxPortProtocol(resource.TargetResource, resolvedEndpoint.Endpoint);\n            AzureSandboxEndpointOptions? resolvedEndpointOptions = null;\n            endpointOptions?.TryGetValue(resolvedEndpoint.Endpoint.Name, out resolvedEndpointOptions);\n            unmatchedEndpointOptions?.Remove(resolvedEndpoint.Endpoint.Name);\n            var endpoint = new SandboxEndpoint(\n                resolvedEndpoint.Endpoint.Name,\n                resolvedTargetPort,\n                IsExternal: true,\n                IsHttp: true,\n                protocol,\n                resolvedEndpointOptions?.Anonymous);\n\n            if (endpoints.TryGetValue(resolvedTargetPort, out var existingEndpoint))\n            {\n                if (!string.Equals(existingEndpoint.Protocol, endpoint.Protocol, StringComparison.Ordinal))\n                {","sourceCodeStart":1488,"sourceCodeEnd":1524,"githubUrl":"https://github.com/microsoft/aspire/blob/25830f84bd145686607ad00c057b3f84e2e51d43/src/Aspire.Hosting.Azure.Sandboxes/AzureSandboxContainerDeployment.cs#L1488-L1524","documentation":"Before wiring a sandbox ingress port, the deployment resolves the endpoint's target port. If ResolveSandboxTargetPort yields null (the endpoint has no target port configured), an InvalidOperationException is thrown because the sandbox must know the concrete container/project port to forward to.","triggerScenarios":"An endpoint is created without WithTargetPort/TargetPort (i.e. a dynamically assigned target port) on a resource being deployed to an Azure sandbox.","commonSituations":"Using WithEndpoint without targetPort and relying on runtime port assignment; endpoints added for local dev only then deployed to sandbox.","solutions":["Configure a fixed target port on the endpoint via WithTargetPort(int) or the targetPort parameter","Ensure the project/container listens on that fixed port","Check the endpoint annotation's TargetPort before deploying"],"exampleFix":"// before\n.WithEndpoint(scheme: \"http\", port: 8080)\n// after\n.WithEndpoint(scheme: \"http\", port: 8080, targetPort: 8080)","handlingStrategy":"validation","validationCode":"if (endpoint.TargetPort is null)\n    throw new InvalidOperationException(\"Endpoint must have a fixed TargetPort before sandbox deployment.\");","typeGuard":"bool HasFixedTargetPort(EndpointAnnotation e) => e.TargetPort is int;","tryCatchPattern":"try { DeploySandbox(...); } catch (InvalidOperationException ex) when (ex.Message.Contains(\"does not have a target port\")) { /* set targetPort on endpoint */ }","preventionTips":["Always pass targetPort in WithEndpoint for sandbox-deployed resources","Avoid relying on dynamic port assignment in deploy scenarios"],"tags":["azure","sandbox","endpoint","port"],"backgroundTag":"missing-required-config-field","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"}