microsoft/aspire · error · ArgumentException
' ' is not a valid value.
Error message
'{roles[i]}' is not a valid {nameof(AzureServiceBusRole)} value. What it means
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.
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.
Example fix
// before sb.WithRoleAssignments(app, (AzureServiceBusRole)99); // after sb.WithRoleAssignments(app, AzureServiceBusRole.AzureServiceBusDataOwner, AzureServiceBusRole.AzureServiceBusDataSender);
Defensive patterns
Strategy: validation
Validate before calling
static readonly AzureServiceBusRole[] AllowedSbRoles =
[
AzureServiceBusRole.AzureServiceBusDataOwner,
AzureServiceBusRole.AzureServiceBusDataReceiver,
AzureServiceBusRole.AzureServiceBusDataSender
];
if (roles.Any(r => !AllowedSbRoles.Contains(r)))
{
throw new ArgumentException("Unsupported AzureServiceBusRole value.");
}
sb.WithRoleAssignments(app, roles); Type guard
static bool IsValidServiceBusRole(AzureServiceBusRole r) =>
r is AzureServiceBusRole.AzureServiceBusDataOwner
or AzureServiceBusRole.AzureServiceBusDataReceiver
or AzureServiceBusRole.AzureServiceBusDataSender; Prevention
- 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.
When it happens
Trigger: Calling WithRoleAssignments on a Service Bus resource with an AzureServiceBusRole value outside the three supported members, including default-initialized or cast values.
Common situations: 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.).
Understand the failure class
Background: Invalid enum value errors: "Unknown type", "Invalid scope", "must be one of" — when a string is not on the library's allowed list — this error's family across 23 libraries.
Related errors
- Invalid Azure AI Search role
- Role ' ' at index is not a valid AzureAppConfigurationRole…
- ' ' is not a valid AzureContainerRegistryRole value.
- ' ' is not a valid AzureKeyVaultRole value.
- ' ' is not a valid value.
AI-assisted analysis of microsoft/aspire@25830f84bd (2026-09-16).
Data as JSON: /api/errors/8d3b799ad6460200.
Report an issue: GitHub.
Appendix: source
Thrown at src/Aspire.Hosting.Azure.ServiceBus/AzureServiceBusExtensions.cs:717
this IResourceBuilder<T> builder,
IResourceBuilder<AzureServiceBusResource> target,
params AzureServiceBusRole[] roles)
where T : IResource
{
if (roles is null || roles.Length == 0)
{
return builder.WithRoleAssignments(target, Array.Empty<ServiceBusBuiltInRole>());
}
var builtInRoles = new ServiceBusBuiltInRole[roles.Length];
for (var i = 0; i < roles.Length; i++)
{
builtInRoles[i] = roles[i] switch
{
AzureServiceBusRole.AzureServiceBusDataOwner => ServiceBusBuiltInRole.AzureServiceBusDataOwner,
AzureServiceBusRole.AzureServiceBusDataReceiver => ServiceBusBuiltInRole.AzureServiceBusDataReceiver,
AzureServiceBusRole.AzureServiceBusDataSender => ServiceBusBuiltInRole.AzureServiceBusDataSender,
_ => throw new ArgumentException($"'{roles[i]}' is not a valid {nameof(AzureServiceBusRole)} value.", nameof(roles))
};
}
return builder.WithRoleAssignments(target, builtInRoles);
}
}
View on GitHub (pinned to 25830f84bd)