{"record":{"id":"654015cb401ce6df","repo":"microsoft/aspire","slug":"roles-i-is-not-a-valid-nameof-azurestoragerole-value","errorCode":null,"errorMessage":"'{roles[i]}' is not a valid {nameof(AzureStorageRole)} value.","messagePattern":"'(.+?)' is not a valid (.+?) value\\.","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"src/Aspire.Hosting.Azure.Storage/AzureStorageExtensions.cs","lineNumber":789,"sourceCode":"                AzureStorageRole.StorageAccountBackupContributor => StorageBuiltInRole.StorageAccountBackupContributor,\n                AzureStorageRole.StorageAccountContributor => StorageBuiltInRole.StorageAccountContributor,\n                AzureStorageRole.StorageAccountKeyOperatorServiceRole => StorageBuiltInRole.StorageAccountKeyOperatorServiceRole,\n                AzureStorageRole.StorageBlobDataContributor => StorageBuiltInRole.StorageBlobDataContributor,\n                AzureStorageRole.StorageBlobDataOwner => StorageBuiltInRole.StorageBlobDataOwner,\n                AzureStorageRole.StorageBlobDataReader => StorageBuiltInRole.StorageBlobDataReader,\n                AzureStorageRole.StorageBlobDelegator => StorageBuiltInRole.StorageBlobDelegator,\n                AzureStorageRole.StorageFileDataPrivilegedContributor => StorageBuiltInRole.StorageFileDataPrivilegedContributor,\n                AzureStorageRole.StorageFileDataPrivilegedReader => StorageBuiltInRole.StorageFileDataPrivilegedReader,\n                AzureStorageRole.StorageFileDataSmbShareContributor => StorageBuiltInRole.StorageFileDataSmbShareContributor,\n                AzureStorageRole.StorageFileDataSmbShareReader => StorageBuiltInRole.StorageFileDataSmbShareReader,\n                AzureStorageRole.StorageFileDataSmbShareElevatedContributor => StorageBuiltInRole.StorageFileDataSmbShareElevatedContributor,\n                AzureStorageRole.StorageQueueDataContributor => StorageBuiltInRole.StorageQueueDataContributor,\n                AzureStorageRole.StorageQueueDataReader => StorageBuiltInRole.StorageQueueDataReader,\n                AzureStorageRole.StorageQueueDataMessageSender => StorageBuiltInRole.StorageQueueDataMessageSender,\n                AzureStorageRole.StorageQueueDataMessageProcessor => StorageBuiltInRole.StorageQueueDataMessageProcessor,\n                AzureStorageRole.StorageTableDataContributor => StorageBuiltInRole.StorageTableDataContributor,\n                AzureStorageRole.StorageTableDataReader => StorageBuiltInRole.StorageTableDataReader,\n                _ => throw new ArgumentException($\"'{roles[i]}' is not a valid {nameof(AzureStorageRole)} value.\", nameof(roles))\n            };\n        }\n\n        return builder.WithRoleAssignments(target, builtInRoles);\n    }\n\n    private static IResourceBuilder<AzureBlobStorageResource> CreateBlobService(IResourceBuilder<AzureStorageResource> builder, string name)\n    {\n        var resource = new AzureBlobStorageResource(name, builder.Resource);\n\n        string? connectionString = null;\n\n        // Add the \"Blobs\" resource health check. This is a separate health check from the \"Storage\" resource health check.\n        // Doing it on the storage is not sufficient as the WaitForHealthyAsync doesn't bubble up to the parent resources.\n        var healthCheckKey = $\"{resource.Name}_check\";\n\n        BlobServiceClient? blobServiceClient = null;\n        builder.ApplicationBuilder.Services.AddHealthChecks().AddAzureBlobStorage(sp =>","sourceCodeStart":771,"sourceCodeEnd":807,"githubUrl":"https://github.com/microsoft/aspire/blob/25830f84bd145686607ad00c057b3f84e2e51d43/src/Aspire.Hosting.Azure.Storage/AzureStorageExtensions.cs#L771-L807","documentation":"WithRoleAssignments maps each AzureStorageRole enum value to a StorageBuiltInRole via a switch expression with no default case for unmapped values; hitting the throw arm means a value outside the recognized set was passed. This guards the API against invalid or future enum members.","triggerScenarios":"Passing an undefined/cast integer as AzureStorageRole, e.g. `(AzureStorageRole)999`, to storage.WithRoleAssignments(...) on the non-emulator path.","commonSituations":"Casting raw ints from config into the enum; consuming an enum value from a different Aspire version that does not exist in the referenced assembly; typo-driven invalid casts.","solutions":["Only pass named AzureStorageRole members (e.g. AzureStorageRole.StorageBlobDataContributor), not cast integers","Compare your enum usage against the members defined in the referenced Aspire.Hosting.Azure.Storage version","Parse untrusted input with Enum.TryParse<AzureStorageRole> before calling WithRoleAssignments"],"exampleFix":"// before\nstorage.WithRoleAssignments(identity, (AzureStorageRole)42);\n// after\nstorage.WithRoleAssignments(identity, AzureStorageRole.StorageBlobDataContributor);","handlingStrategy":"validation","validationCode":"if (!Enum.IsDefined(typeof(AzureStorageRole), role))\n    throw new ArgumentException($\"'{role}' is not a defined AzureStorageRole value.\");","typeGuard":"static bool IsValidStorageRole(AzureStorageRole role) => Enum.IsDefined(role);","tryCatchPattern":"try { storage.WithRoleAssignments(identity, roles); }\ncatch (ArgumentException ex) when (ex.Message.Contains(\"not a valid AzureStorageRole\")) { /* log and surface invalid role */ }","preventionTips":["Use named enum members only; never cast integers or strings into AzureStorageRole","Parse untrusted role input with Enum.TryParse before calling WithRoleAssignments","Match enum member usage to the exact package version referenced"],"tags":["azure-storage","enum","role-assignments","argument-validation"],"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"}