{"record":{"id":"7563032b5932698a","repo":"microsoft/aspire","slug":"role-roles-i-at-index-i-is-not-a-valid","errorCode":null,"errorMessage":"Role '{roles[i]}' at index {i} is not a valid AzureAppConfigurationRole value.","messagePattern":"Role '(.+?)' at index (.+?) is not a valid AzureAppConfigurationRole value\\.","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"src/Aspire.Hosting.Azure.AppConfiguration/AzureAppConfigurationExtensions.cs","lineNumber":240,"sourceCode":"    internal static IResourceBuilder<T> WithRoleAssignments<T>(\n        this IResourceBuilder<T> builder,\n        IResourceBuilder<AzureAppConfigurationResource> target,\n        params AzureAppConfigurationRole[] roles)\n        where T : IResource\n    {\n        if (roles is null || roles.Length == 0)\n        {\n            return builder.WithRoleAssignments(target, Array.Empty<AppConfigurationBuiltInRole>());\n        }\n\n        var builtInRoles = new AppConfigurationBuiltInRole[roles.Length];\n        for (var i = 0; i < roles.Length; i++)\n        {\n            builtInRoles[i] = roles[i] switch\n            {\n                AzureAppConfigurationRole.AppConfigurationDataOwner => AppConfigurationBuiltInRole.AppConfigurationDataOwner,\n                AzureAppConfigurationRole.AppConfigurationDataReader => AppConfigurationBuiltInRole.AppConfigurationDataReader,\n                _ => throw new ArgumentException($\"Role '{roles[i]}' at index {i} is not a valid {nameof(AzureAppConfigurationRole)} value.\", nameof(roles))\n            };\n        }\n\n        return builder.WithRoleAssignments(target, builtInRoles);\n    }\n\n    /// <summary>\n    /// Configures anonymous authentication for the Azure App Configuration emulator resource.\n    /// </summary>\n    /// <param name=\"builder\">The resource builder for the Azure App Configuration emulator.</param>\n    /// <param name=\"role\">The role to assign to the anonymous user. Defaults to \"Owner\".</param>\n    /// <returns>The updated resource builder for further configuration.</returns>\n    internal static IResourceBuilder<AzureAppConfigurationEmulatorResource> WithAnonymousAccess(this IResourceBuilder<AzureAppConfigurationEmulatorResource> builder, string role = \"Owner\")\n    {\n        builder.WithEnvironment(\"Tenant:AnonymousAuthEnabled\", \"true\");\n        builder.WithEnvironment(\"Authentication:Anonymous:AnonymousUserRole\", role);\n        return builder;\n    }","sourceCodeStart":222,"sourceCodeEnd":258,"githubUrl":"https://github.com/microsoft/aspire/blob/25830f84bd145686607ad00c057b3f84e2e51d43/src/Aspire.Hosting.Azure.AppConfiguration/AzureAppConfigurationExtensions.cs#L222-L258","documentation":"WithRoleAssignments maps the public AzureAppConfigurationRole enum to the underlying AppConfigurationBuiltInRole. Any value outside the two known enum members falls into the default arm and throws this ArgumentException naming the offending role and its index in the roles array.","triggerScenarios":"Calling WithRoleAssignments(builder, target, params AzureAppConfigurationRole[]) with a value that is not AzureAppConfigurationRole.AppConfigurationDataOwner or AppConfigurationDataReader — typically an invalid cast, a hardcoded integer cast to the enum, or an enum member added in a newer package version while the extension maps only known members.","commonSituations":"Developers casting arbitrary ints to AzureAppConfigurationRole, copying role code from other Azure integrations (e.g. Cosmos/Key Vault role enums) and passing them here, or SDK upgrades introducing new roles the installed extension version does not yet support.","solutions":["Pass only AzureAppConfigurationRole.AppConfigurationDataOwner or AzureAppConfigurationRole.AppConfigurationDataReader","Remove invalid casts; construct roles as explicit enum values, not ints","Upgrade the Aspire.Hosting.Azure.AppConfiguration package if you need newly added roles"],"exampleFix":"// before\nbuilder.AddAzureAppConfiguration(\"config\").WithRoleAssignments(appConfig, (AzureAppConfigurationRole)5);\n// after\nbuilder.AddAzureAppConfiguration(\"config\").WithRoleAssignments(appConfig, AzureAppConfigurationRole.AppConfigurationDataOwner);","handlingStrategy":"validation","validationCode":"if (!Enum.IsDefined(typeof(AzureAppConfigurationRole), role))\n{\n    throw new ArgumentException($\"Unsupported role {role}\", nameof(roles));\n}","typeGuard":"static bool IsValidAppConfigRole(AzureAppConfigurationRole role) =>\n    role is AzureAppConfigurationRole.AppConfigurationDataOwner\n         or AzureAppConfigurationRole.AppConfigurationDataReader;","tryCatchPattern":"try { builder.WithRoleAssignments(appConfig, roles); }\ncatch (ArgumentException ex)\n{\n    logger.LogError(ex, \"Invalid AzureAppConfigurationRole supplied\");\n}","preventionTips":["Use explicit enum values, never int casts","Restrict inputs to documented role members","Recheck supported roles after upgrading the package"],"tags":["azure","app-configuration","enum","role-assignments"],"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"}