{"record":{"id":"01be10ae864fc9ff","repo":"microsoft/aspire","slug":"unsupported-azure-sandbox-tier-options-tier","errorCode":null,"errorMessage":"Unsupported Azure sandbox tier '{options?.Tier}'.","messagePattern":"Unsupported Azure sandbox tier '(.+?)'\\.","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"src/Aspire.Hosting.Azure.Sandboxes/AzureSandboxContainerDeployment.cs","lineNumber":815,"sourceCode":"            appIdentityAnnotation.IdentityResource is not AzureUserAssignedIdentityResource userAssignedIdentity)\n        {\n            return;\n        }\n\n        environmentVariables.TryAdd(\"AZURE_CLIENT_ID\", GetRequiredOutput(userAssignedIdentity, \"clientId\"));\n    }\n\n    internal static AzureDevComputeSandboxResources CreateSandboxResources(AzureSandboxContainerResource resource)\n    {\n        var options = GetAzureSandboxContainerOptions(resource.TargetResource);\n        return (options?.Tier ?? AzureSandboxTier.Medium) switch\n        {\n            AzureSandboxTier.ExtraSmall => new() { Cpu = \"250m\", Memory = \"512Mi\", Disk = \"20480Mi\" },\n            AzureSandboxTier.Small => new() { Cpu = \"500m\", Memory = \"1024Mi\", Disk = \"20480Mi\" },\n            AzureSandboxTier.Medium => new() { Cpu = \"1000m\", Memory = \"2048Mi\", Disk = \"20480Mi\" },\n            AzureSandboxTier.Large => new() { Cpu = \"2000m\", Memory = \"4096Mi\", Disk = \"40960Mi\" },\n            AzureSandboxTier.ExtraLarge => new() { Cpu = \"4000m\", Memory = \"8192Mi\", Disk = \"81920Mi\" },\n            _ => throw new InvalidOperationException($\"Unsupported Azure sandbox tier '{options?.Tier}'.\")\n        };\n    }\n\n    internal static AzureDevComputeSandboxEgressPolicy CreateEgressPolicy(IEnumerable<string> allowedHosts)\n    {\n        var normalizedHosts = allowedHosts\n            .Where(static host => Uri.CheckHostName(host) is not UriHostNameType.Unknown)\n            .Where(IsOutboundHost)\n            .Distinct(StringComparer.OrdinalIgnoreCase)\n            .Order(StringComparer.OrdinalIgnoreCase)\n            .ToArray();\n\n        return new AzureDevComputeSandboxEgressPolicy\n        {\n            DefaultAction = \"Deny\",\n            TrafficInspection = \"Full\",\n            HostRules =\n            [","sourceCodeStart":797,"sourceCodeEnd":833,"githubUrl":"https://github.com/microsoft/aspire/blob/25830f84bd145686607ad00c057b3f84e2e51d43/src/Aspire.Hosting.Azure.Sandboxes/AzureSandboxContainerDeployment.cs#L797-L833","documentation":"The sandbox tier selection uses a switch expression over AzureSandboxTier with resource sizes for ExtraSmall through ExtraLarge; any other value falls to the default arm, which throws InvalidOperationException naming the supplied tier. This guards against invalid casts or out-of-range enum values.","triggerScenarios":"Configuring AzureSandboxOptions.Tier with an invalid value — typically an out-of-range int cast to AzureSandboxTier, a deserialized garbage value from config/JSON, or a newer enum member not yet handled by this switch.","commonSituations":"Loading sandbox options from environment variables or appsettings where the tier is parsed from a string/number without validation, or version skew between a newer CLI writing a tier value the deployment code does not know.","solutions":["Set Tier to one of the supported values: ExtraSmall, Small, Medium, Large, or ExtraLarge.","Validate/normalize the tier when reading it from config (parse with Enum.TryParse and reject unknown values).","If you genuinely need a new tier, it must be added to the switch in CreateSandboxSpec; otherwise use the nearest supported size."],"exampleFix":"// before\noptions.Tier = (AzureSandboxTier)7; // undefined\n// after\noptions.Tier = AzureSandboxTier.Large;","handlingStrategy":"validation","validationCode":"static bool IsSupportedTier(AzureSandboxTier t) =>\n    t is AzureSandboxTier.ExtraSmall or AzureSandboxTier.Small\n        or AzureSandboxTier.Medium or AzureSandboxTier.Large\n        or AzureSandboxTier.ExtraLarge;","typeGuard":"bool TryParseTier(string? s, out AzureSandboxTier tier) =>\n    Enum.TryParse(s, ignoreCase: true, out tier) && IsSupportedTier(tier);","tryCatchPattern":"try { await deployment.DeployAsync(...); }\ncatch (InvalidOperationException ex) when (ex.Message.StartsWith(\"Unsupported Azure sandbox tier\"))\n{ /* correct options.Tier to a supported value and retry */ }","preventionTips":["Parse tiers with Enum.TryParse plus a supported-values whitelist.","Never cast raw ints/strings to AzureSandboxTier without validation.","Keep tier config values in sync with the enum versions in use."],"tags":["azure","sandboxes","enum","configuration"],"backgroundTag":"invalid-enum-value","analyzedSha":"25830f84bd145686607ad00c057b3f84e2e51d43","analyzedAt":"2026-09-16T11:10:06.193Z","contentChangedAt":"2026-09-16T11:10:06.193Z","schemaVersion":2},"datasetVersion":"2026-09-21T09:17:21.228Z"}