{"record":{"id":"65838bbdc8b3c868","repo":"dotnet/orleans","slug":"website-private-ports-must-contain-at-least-one-tc","errorCode":null,"errorMessage":"WEBSITE_PRIVATE_PORTS must contain at least one TCP port.","messagePattern":"WEBSITE_PRIVATE_PORTS must contain at least one TCP port\\.","errorType":"validation","errorClass":"InvalidOperationException","httpStatus":null,"severity":"critical","filePath":"samples/Deployment/AzureAppService/Silo/Program.cs","lineNumber":109,"sourceCode":"app.MapBlazorHub();\napp.MapFallbackToPage(\"/_Host\");\n\nawait app.RunAsync();\n\nstatic void ConfigureProductionOrleans(WebApplicationBuilder builder)\n{\n    var clusterId = GetRequiredSetting(builder, \"ORLEANS_CLUSTER_ID\");\n    var serviceId = GetRequiredSetting(builder, \"ORLEANS_SERVICE_ID\");\n    var storageUri = new Uri(GetRequiredSetting(builder, \"ORLEANS_AZURE_STORAGE_URI\"));\n    var managedIdentityClientId = GetRequiredSetting(builder, \"AZURE_CLIENT_ID\");\n    var privateIp = IPAddress.Parse(GetRequiredSetting(builder, \"WEBSITE_PRIVATE_IP\"));\n    var privatePorts = GetRequiredSetting(builder, \"WEBSITE_PRIVATE_PORTS\")\n        .Split(',', StringSplitOptions.RemoveEmptyEntries | StringSplitOptions.TrimEntries);\n\n    if (privatePorts.Length < 1\n        || !int.TryParse(privatePorts[0], NumberStyles.None, CultureInfo.InvariantCulture, out var siloPort))\n    {\n        throw new InvalidOperationException(\n            \"WEBSITE_PRIVATE_PORTS must contain at least one TCP port.\");\n    }\n\n    var credential = new DefaultAzureCredential(new DefaultAzureCredentialOptions\n    {\n        ManagedIdentityClientId = managedIdentityClientId,\n    });\n    var tableServiceClient = new TableServiceClient(storageUri, credential);\n\n    builder.UseOrleans(siloBuilder =>\n    {\n        siloBuilder\n            .Configure<SiloOptions>(options =>\n            {\n                options.SiloName = builder.Configuration[\"WEBSITE_INSTANCE_ID\"]\n                    ?? Environment.MachineName;\n            })\n            .Configure<ClusterOptions>(options =>","sourceCodeStart":91,"sourceCodeEnd":127,"githubUrl":"https://github.com/dotnet/orleans/blob/fca799fa70ecb6ad975224271703ca43221f58de/samples/Deployment/AzureAppService/Silo/Program.cs#L91-L127","documentation":"An InvalidOperationException thrown by the Azure App Service silo host when the WEBSITE_PRIVATE_PORTS setting is missing or its first comma-separated value cannot be parsed as a TCP port. Azure App Service injects WEBSITE_PRIVATE_PORTS to tell the silo which private ports to bind; the code parses the first as the silo port with NumberStyles.None (unsigned integer). If parsing fails or the array is empty, startup aborts.","triggerScenarios":"Silo startup in an Azure App Service where WEBSITE_PRIVATE_PORTS is unset, empty, or contains a non-numeric/signed value in position 0. The Split + int.TryParse(NumberStyles.None) guard catches both 'no ports' and 'unparseable port'.","commonSituations":"Running the sample outside Azure App Service (the env var is never set). A corrupted/misconfigured app setting. The App Service plan variant not injecting the variable as expected.","solutions":["Deploy/run the silo inside an Azure App Service so the platform injects WEBSITE_PRIVATE_PORTS automatically.","If running locally, set WEBSITE_PRIVATE_PORTS to a valid port (e.g., '11111') in environment/launchSettings for testing.","Verify the value has no stray characters/signs — NumberStyles.None rejects '+','-', whitespace, and hex."],"exampleFix":"// before\nif (privatePorts.Length < 1\n    || !int.TryParse(privatePorts[0], NumberStyles.None, CultureInfo.InvariantCulture, out var siloPort))\n{\n    throw new InvalidOperationException(\"WEBSITE_PRIVATE_PORTS must contain at least one TCP port.\");\n}\n\n// after (explicit, actionable error)\nif (privatePorts.Length < 1)\n    throw new InvalidOperationException(\"WEBSITE_PRIVATE_PORTS is empty; configure at least one private TCP port in the App Service.\");\nif (!int.TryParse(privatePorts[0], NumberStyles.None, CultureInfo.InvariantCulture, out var siloPort))\n    throw new InvalidOperationException($\"WEBSITE_PRIVATE_PORTS[0] = '{privatePorts[0]}' is not a valid TCP port.\");","handlingStrategy":"validation","validationCode":"var raw = builder.Configuration[\"WEBSITE_PRIVATE_PORTS\"];\nvar ports = raw?.Split(',', StringSplitOptions.RemoveEmptyEntries | StringSplitOptions.TrimEntries);\nif (ports is null || ports.Length == 0 || !int.TryParse(ports[0], NumberStyles.None, CultureInfo.InvariantCulture, out _))\n    throw new InvalidOperationException(\"WEBSITE_PRIVATE_PORTS must contain at least one TCP port.\");","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Run the silo inside Azure App Service so the platform injects WEBSITE_PRIVATE_PORTS.","For local tests, set the variable explicitly to a valid port.","Avoid non-numeric characters; NumberStyles.None rejects signs/whitespace/hex."],"tags":["deployment","azure-app-service","configuration","startup","validation"],"backgroundTag":null,"analyzedSha":"fca799fa70ecb6ad975224271703ca43221f58de","analyzedAt":"2026-08-13T19:55:57.938Z","schemaVersion":2},"datasetVersion":"2026-08-14T05:17:29.042Z"}