{"record":{"id":"d4b0938fc6efdc1f","repo":"microsoft/aspire","slug":"endpoint-endpoint-name-must-specify-a-port-for-scheme-scheme-d4b093","errorCode":null,"errorMessage":"Endpoint '{endpoint.Name}' must specify a port for scheme '{scheme}'.","messagePattern":"Endpoint '(.+?)' must specify a port for scheme '(.+?)'\\.","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"src/Aspire.Hosting/ApplicationModel/IComputeEnvironmentResource.cs","lineNumber":80,"sourceCode":"            EndpointProperty.HostAndPort => ReferenceExpression.Create($\"{host.Value}:{port.ToString(CultureInfo.InvariantCulture)}\"),\n            EndpointProperty.TlsEnabled => ReferenceExpression.Create($\"{(endpoint.TlsEnabled ? bool.TrueString : bool.FalseString)}\"),\n            _ => throw new InvalidOperationException($\"The property '{property}' is not supported for the endpoint '{endpoint.Name}'.\")\n        };\n    }\n\n    private static int GetDefaultPort(string scheme, EndpointAnnotation endpoint)\n    {\n        if (string.Equals(scheme, \"http\", StringComparison.OrdinalIgnoreCase))\n        {\n            return 80;\n        }\n\n        if (string.Equals(scheme, \"https\", StringComparison.OrdinalIgnoreCase))\n        {\n            return 443;\n        }\n\n        throw new InvalidOperationException($\"Endpoint '{endpoint.Name}' must specify a port for scheme '{scheme}'.\");\n    }\n\n    private static bool IsDefaultPort(string scheme, int port)\n    {\n        return string.Equals(scheme, \"http\", StringComparison.OrdinalIgnoreCase) && port == 80 ||\n            string.Equals(scheme, \"https\", StringComparison.OrdinalIgnoreCase) && port == 443;\n    }\n}\n","sourceCodeStart":62,"sourceCodeEnd":89,"githubUrl":"https://github.com/microsoft/aspire/blob/25830f84bd145686607ad00c057b3f84e2e51d43/src/Aspire.Hosting/ApplicationModel/IComputeEnvironmentResource.cs#L62-L89","documentation":"GetDefaultPort supplies conventional ports for http (80) and https (443) when an endpoint has no explicit port. For any other scheme it cannot infer a default, so it throws InvalidOperationException telling the developer the endpoint must specify a port explicitly via WithEndpoint/EndpointAnnotation.","triggerScenarios":"Evaluating an endpoint property (host:port expression, manifest generation) for an endpoint whose Scheme is neither http nor https and whose TargetPort/Port is null.","commonSituations":"Custom schemes like 'tcp', 'grpc', or 'amqp' registered with WithEndpoint but without a port; endpoints declared for port-forwarding where the container exposes no fixed port; typo'd scheme names ('https ' or 'HTTPs2').","solutions":["Specify the port explicitly: builder.AddXyz(\"name\").WithEndpoint(scheme: \"tcp\", port: 5672, targetPort: 5672).","Use the standard 'http'/'https' schemes when default ports (80/443) are what you want.","Fix the scheme name if it was a typo of http/https.","Catch InvalidOperationException during manifest generation to report which endpoint/scheme needs a port."],"exampleFix":"// before\n.WithEndpoint(scheme: \"grpc\") // no port -> throws on property evaluation\n// after\n.WithEndpoint(scheme: \"grpc\", port: 5001, targetPort: 5001)","handlingStrategy":"validation","validationCode":"// before evaluating endpoint properties\nstatic bool HasResolvablePort(EndpointAnnotation e) =>\n    e.TargetPort is int || e.Port is int ||\n    string.Equals(e.Scheme, \"http\", StringComparison.OrdinalIgnoreCase) ||\n    string.Equals(e.Scheme, \"https\", StringComparison.OrdinalIgnoreCase);","typeGuard":null,"tryCatchPattern":"try\n{\n    var expr = env.GetEndpointPropertyExpression(endpoint, EndpointProperty.HostAndPort);\n}\ncatch (InvalidOperationException ex) when (ex.Message.Contains(\"must specify a port\"))\n{\n    // instruct user to call WithEndpoint(port: ...) for non-http(s) schemes\n}","preventionTips":["Always pass port (and targetPort) when using custom schemes like tcp/grpc/amqp.","Reserve http/https schemes for endpoints relying on default ports 80/443.","Check endpoint.Scheme in custom resources before assuming a default port exists.","Catch this at manifest generation and emit a clear 'endpoint X needs a port' diagnostic."],"tags":["dotnet","aspire","endpoints","ports","compute-environment"],"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"}