{"record":{"id":"8d3b799ad6460200","repo":"microsoft/aspire","slug":"roles-i-is-not-a-valid-nameof-azureservicebusrole-value","errorCode":null,"errorMessage":"'{roles[i]}' is not a valid {nameof(AzureServiceBusRole)} value.","messagePattern":"'(.+?)' is not a valid (.+?) value\\.","errorType":"validation","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"src/Aspire.Hosting.Azure.ServiceBus/AzureServiceBusExtensions.cs","lineNumber":717,"sourceCode":"        this IResourceBuilder<T> builder,\n        IResourceBuilder<AzureServiceBusResource> target,\n        params AzureServiceBusRole[] roles)\n        where T : IResource\n    {\n        if (roles is null || roles.Length == 0)\n        {\n            return builder.WithRoleAssignments(target, Array.Empty<ServiceBusBuiltInRole>());\n        }\n\n        var builtInRoles = new ServiceBusBuiltInRole[roles.Length];\n        for (var i = 0; i < roles.Length; i++)\n        {\n            builtInRoles[i] = roles[i] switch\n            {\n                AzureServiceBusRole.AzureServiceBusDataOwner => ServiceBusBuiltInRole.AzureServiceBusDataOwner,\n                AzureServiceBusRole.AzureServiceBusDataReceiver => ServiceBusBuiltInRole.AzureServiceBusDataReceiver,\n                AzureServiceBusRole.AzureServiceBusDataSender => ServiceBusBuiltInRole.AzureServiceBusDataSender,\n                _ => throw new ArgumentException($\"'{roles[i]}' is not a valid {nameof(AzureServiceBusRole)} value.\", nameof(roles))\n            };\n        }\n\n        return builder.WithRoleAssignments(target, builtInRoles);\n    }\n}\n","sourceCodeStart":699,"sourceCodeEnd":724,"githubUrl":"https://github.com/microsoft/aspire/blob/25830f84bd145686607ad00c057b3f84e2e51d43/src/Aspire.Hosting.Azure.ServiceBus/AzureServiceBusExtensions.cs#L699-L724","documentation":"WithRoleAssignments for Azure Service Bus maps each AzureServiceBusRole to a provisioning ServiceBusBuiltInRole; only AzureServiceBusDataOwner, AzureServiceBusDataReceiver, and AzureServiceBusDataSender are supported. Any other value throws ArgumentException naming the invalid element and the expected enum type.","triggerScenarios":"Calling WithRoleAssignments on a Service Bus resource with an AzureServiceBusRole value outside the three supported members, including default-initialized or cast values.","commonSituations":"Passing default(AzureServiceBusRole) or an out-of-range cast; package versions where a newer enum member lacks a mapping; mixing up role enums from other Azure resources (Search, Storage, etc.).","solutions":["Use only AzureServiceBusRole.AzureServiceBusDataOwner, AzureServiceBusDataReceiver, or AzureServiceBusDataSender.","Fix the element at index i named in the exception message.","Update Aspire.Hosting.Azure.ServiceBus to the latest version if a newer role is needed.","Use the underlying provisioning API directly for roles not covered by the extension."],"exampleFix":"// before\nsb.WithRoleAssignments(app, (AzureServiceBusRole)99);\n// after\nsb.WithRoleAssignments(app, AzureServiceBusRole.AzureServiceBusDataOwner, AzureServiceBusRole.AzureServiceBusDataSender);","handlingStrategy":"validation","validationCode":"static readonly AzureServiceBusRole[] AllowedSbRoles =\n[\n    AzureServiceBusRole.AzureServiceBusDataOwner,\n    AzureServiceBusRole.AzureServiceBusDataReceiver,\n    AzureServiceBusRole.AzureServiceBusDataSender\n];\n\nif (roles.Any(r => !AllowedSbRoles.Contains(r)))\n{\n    throw new ArgumentException(\"Unsupported AzureServiceBusRole value.\");\n}\nsb.WithRoleAssignments(app, roles);","typeGuard":"static bool IsValidServiceBusRole(AzureServiceBusRole r) =>\n    r is AzureServiceBusRole.AzureServiceBusDataOwner\n      or AzureServiceBusRole.AzureServiceBusDataReceiver\n      or AzureServiceBusRole.AzureServiceBusDataSender;","tryCatchPattern":null,"preventionTips":["Use only the three supported AzureServiceBusRole members; never cast integers into the enum.","Do not mix role enums from other Azure resources into Service Bus calls.","Update the package when new roles are released.","Centralize role-assignment configuration for validation in one place."],"tags":["azure","servicebus","role-assignments","enum"],"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-21T04:17:39.646Z"}