{"record":{"id":"1d56450fcdb8148b","repo":"dotnet/orleans","slug":"key-must-be-a-valid-tcp-port","errorCode":null,"errorMessage":"{key} must be a valid TCP port.","messagePattern":"(.+?) must be a valid TCP port\\.","errorType":"validation","errorClass":"InvalidOperationException","httpStatus":null,"severity":"critical","filePath":"samples/Deployment/AzureContainerApps/Infrastructure/OrleansEndpointConfigurationExtensions.cs","lineNumber":49,"sourceCode":"        var advertisedGatewayPort = GetRequiredPort(configuration, \"Orleans:AdvertisedGatewayPort\");\n\n        return siloBuilder.Configure<EndpointOptions>(options =>\n        {\n            options.AdvertisedIPAddress = advertisedIp;\n            options.SiloPort = advertisedSiloPort;\n            options.GatewayPort = advertisedGatewayPort;\n            options.SiloListeningEndpoint = new IPEndPoint(IPAddress.Any, 11_111);\n            options.GatewayListeningEndpoint = new IPEndPoint(IPAddress.Any, 30_000);\n        });\n    }\n\n    private static int GetRequiredPort(IConfiguration configuration, string key)\n    {\n        var value = AzureTableServiceClientFactory.GetRequiredValue(configuration, key);\n        if (!int.TryParse(value, NumberStyles.None, CultureInfo.InvariantCulture, out var port)\n            || port is < 1 or > IPEndPoint.MaxPort)\n        {\n            throw new InvalidOperationException($\"{key} must be a valid TCP port.\");\n        }\n\n        return port;\n    }\n}\n","sourceCodeStart":31,"sourceCodeEnd":55,"githubUrl":"https://github.com/dotnet/orleans/blob/fca799fa70ecb6ad975224271703ca43221f58de/samples/Deployment/AzureContainerApps/Infrastructure/OrleansEndpointConfigurationExtensions.cs#L31-L55","documentation":"An InvalidOperationException thrown by GetRequiredPort when an Orleans advertised port setting (Orleans:AdvertisedSiloPort or Orleans:AdvertisedGatewayPort) is missing or not a valid unsigned TCP port in the range 1..65535. The value is parsed with NumberStyles.None (no sign) and range-checked against IPEndPoint.MaxPort.","triggerScenarios":"A port key is unset, non-numeric, negative, zero, or > 65535. The int.TryParse fails or the 'is < 1 or > MaxPort' pattern matches.","commonSituations":"Port env vars not provisioned in the container app. A value like '0', '-1', '65536', or a string. Misnamed keys so GetRequiredValue returns the not-configured error first.","solutions":["Set both Orleans:AdvertisedSiloPort and Orleans:AdvertisedGatewayPort to integers in 1..65535.","Ensure the values are plain unsigned integers (no '+', '-', whitespace, hex).","Confirm the container app exposes/permits those ports in its ingress/ports config."],"exampleFix":"// before (config)\n\"Orleans\": { \"AdvertisedSiloPort\": \"0\", \"AdvertisedGatewayPort\": \"30000\" }\n\n// after\n\"Orleans\": { \"AdvertisedSiloPort\": \"11111\", \"AdvertisedGatewayPort\": \"30000\" }","handlingStrategy":"validation","validationCode":"static int CheckPort(IConfiguration c, string key) {\n    var v = c[key];\n    if (!int.TryParse(v, NumberStyles.None, CultureInfo.InvariantCulture, out var p) || p is < 1 or > IPEndPoint.MaxPort)\n        throw new InvalidOperationException($\"{key} must be a TCP port in 1..65535.\");\n    return p;\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Set advertised ports to plain unsigned integers within 1..65535.","Ensure the container app exposes those ports.","Validate ports in a startup config check before binding endpoints."],"tags":["orleans","configuration","networking","azure-container-apps","validation","startup"],"backgroundTag":null,"analyzedSha":"fca799fa70ecb6ad975224271703ca43221f58de","analyzedAt":"2026-08-13T19:55:57.938Z","schemaVersion":2},"datasetVersion":"2026-08-14T00:17:13.853Z"}