{"record":{"id":"05e4599e0c7446c8","repo":"microsoft/aspire","slug":"endpoint-endpointreferenceexpression-endpoint-endpointname","errorCode":null,"errorMessage":"Endpoint '{endpointReferenceExpression.Endpoint.EndpointName}' on resource '{resource.TargetResource.Name}' does not have a target port.","messagePattern":"Endpoint '(.+?)' on resource '(.+?)' does not have a target port\\.","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"src/Aspire.Hosting.Azure.Sandboxes/AzureSandboxEndpointPropertyValueProvider.cs","lineNumber":35,"sourceCode":"{\n    private readonly AzureSandboxContainerResource _resource;\n    private readonly EndpointReferenceExpression _endpointReferenceExpression;\n    private readonly AzureSandboxContainerDeployment.SandboxEndpoint? _sandboxEndpoint;\n    private readonly int _targetPort;\n\n    public AzureSandboxEndpointPropertyValueProvider(\n        AzureSandboxContainerResource resource,\n        EndpointReferenceExpression endpointReferenceExpression)\n    {\n        ArgumentNullException.ThrowIfNull(resource);\n        ArgumentNullException.ThrowIfNull(endpointReferenceExpression);\n\n        _resource = resource;\n        _endpointReferenceExpression = endpointReferenceExpression;\n        if (endpointReferenceExpression.Property == EndpointProperty.TargetPort)\n        {\n            _targetPort = ResolveEndpointTargetPort(resource, endpointReferenceExpression.Endpoint.EndpointName) ??\n                throw new InvalidOperationException($\"Endpoint '{endpointReferenceExpression.Endpoint.EndpointName}' on resource '{resource.TargetResource.Name}' does not have a target port.\");\n        }\n        else\n        {\n            var sandboxEndpoint = ResolveSandboxEndpoint(resource, endpointReferenceExpression.Endpoint);\n            _sandboxEndpoint = sandboxEndpoint;\n            _targetPort = sandboxEndpoint.TargetPort;\n        }\n    }\n\n    public string ValueExpression =>\n        $\"{{{_resource.Name}.endpoints.{_endpointReferenceExpression.Endpoint.EndpointName}.{_endpointReferenceExpression.Property.ToString().ToLowerInvariant()}}}\";\n\n    public ValueTask<string?> GetValueAsync(CancellationToken cancellationToken = default)\n    {\n        return new(GetKnownValueWithoutDeploymentState() ?? throw CreateUnresolvedEndpointException());\n    }\n\n    public async ValueTask<string?> GetValueAsync(ValueProviderContext context, CancellationToken cancellationToken = default)","sourceCodeStart":17,"sourceCodeEnd":53,"githubUrl":"https://github.com/microsoft/aspire/blob/25830f84bd145686607ad00c057b3f84e2e51d43/src/Aspire.Hosting.Azure.Sandboxes/AzureSandboxEndpointPropertyValueProvider.cs#L17-L53","documentation":"Thrown when constructing an AzureSandboxEndpointPropertyValueProvider for an EndpointProperty.TargetPort expression whose endpoint has no resolvable target port on the target resource. The provider needs the container's internal target port to map sandbox URLs back to the endpoint and cannot proceed without it.","triggerScenarios":"ResolveEndpointTargetPort(resource, endpointName) returns null — the endpoint on resource.TargetResource has no explicit TargetPort and none can be inferred (e.g. an endpoint declared without WithTargetPort or without a container port binding).","commonSituations":"Declaring `.WithEndpoint(...)` or `.WithHttpEndpoint(...)` without a target port on a container used as an Azure sandbox container; referencing an endpoint name that was renamed or misspelled.","solutions":["Add an explicit target port to the endpoint: .WithHttpEndpoint(port: 8080, targetPort: 8080, name: \"http\").","Verify the endpoint name in the EndpointReference matches the name passed to WithHttpEndpoint/WithEndpoint.","If the container image exposes a fixed port, set targetPort to that container port explicitly.","Check resource.TargetResource.ResolveEndpoints() in a debug session to see which endpoints/ports were actually registered."],"exampleFix":"// before\nbuilder.AddContainer(\"api\", \"image\").WithHttpEndpoint(name: \"http\");\n// after\nbuilder.AddContainer(\"api\", \"image\").WithHttpEndpoint(targetPort: 8080, name: \"http\");","handlingStrategy":"validation","validationCode":"bool HasTargetPort(IResource r, string endpointName) =>\n    r.ResolveEndpoints().Any(e => e.EndpointName == endpointName && e.TargetPort is not null);","typeGuard":null,"tryCatchPattern":"try { var value = await provider.GetValueAsync(); }\ncatch (InvalidOperationException ex) { logger.LogError(ex, \"Endpoint missing target port\"); throw; }","preventionTips":["Always pass an explicit targetPort when declaring container endpoints used by sandboxes.","Align targetPort with the image's exposed container port.","Keep endpoint names consistent across declarations and references."],"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"}