microsoft/aspire · error · InvalidOperationException

A recipe parameter on Radius environment

Error message

A recipe parameter on Radius environment '{_environment.Name}' references Azure provider configuration, but no Azure provider is configured. Call WithAzureProvider(...) on the environment.

What it means

A recipe parameter on the Radius environment references the Azure provider's SubscriptionId scope field, but the environment has no Azure provider configured, so `providers?.Azure?.SubscriptionId` is null and the switch arm throws MissingProviderReference("Azure", "WithAzureProvider"). Publish stops early with an actionable message rather than producing a manifest with an unresolved Azure scope.

Solutions

  1. Call .WithAzureProvider(...) on the environment with subscription id (and resource group) configured.
  2. Confirm the RadiusCloudProvidersAnnotation carries Azure.SubscriptionId after configuration.
  3. Change the recipe parameter's scope field if it should not resolve Azure subscription scope.
  4. Republish and verify the environment manifest lists the azure provider with subscription.

Example fix

// before
var env = builder.AddRadiusEnvironment("env"); // Azure recipe param needs SubscriptionId

// after
var env = builder.AddRadiusEnvironment("env")
                 .WithAzureProvider(subscriptionId: "sub-guid", resourceGroup: "rg-app");
Defensive patterns

Strategy: validation

Validate before calling

var ann = environment.Annotations.OfType<RadiusCloudProvidersAnnotation>().FirstOrDefault();
if (ann?.Azure?.SubscriptionId is null) throw new InvalidOperationException("Environment needs .WithAzureProvider(...) with a subscription id before Azure-scoped recipes.");

Try / catch

try {
  await publishPipeline.ExecuteAsync(ct);
} catch (InvalidOperationException ex) when (ex.Message.Contains("WithAzureProvider")) {
  // register the Azure provider on the environment and republish
}

Prevention

When it happens

Trigger: Publishing when a recipe parameter resolves RadiusProviderScopeField.SubscriptionId on an environment without `.WithAzureProvider(...)` (annotation missing or Azure block null) — thrown at RadiusInfrastructureBuilder.cs:5479.

Common situations: Environment created for local/AWS use then reused for Azure recipes; WithAzureProvider omitted or given without subscription; environment setup copied from a template that only registered the AWS provider.

Related errors


AI-assisted analysis of microsoft/aspire@25830f84bd (2026-09-16). Data as JSON: /api/errors/fc02ffbffc2a1f14. Report an issue: GitHub.

Appendix: source

Thrown at src/Aspire.Hosting.Radius/Publishing/RadiusInfrastructureBuilder.cs:5479

    /// <summary>
    /// Resolves a <see cref="RadiusProviderReference"/> to the corresponding scope value from the
    /// cloud provider configured on this environment. Throws when the referenced provider is not
    /// configured.
    /// </summary>
    private string ResolveProviderReference(RadiusProviderReference reference)
    {
        var providers = _environment.Annotations
            .OfType<Annotations.RadiusCloudProvidersAnnotation>()
            .FirstOrDefault();

        return reference.Field switch
        {
            RadiusProviderScopeField.Region =>
                providers?.Aws?.Region ?? throw MissingProviderReference("AWS", "WithAwsProvider"),
            RadiusProviderScopeField.AccountId =>
                providers?.Aws?.AccountId ?? throw MissingProviderReference("AWS", "WithAwsProvider"),
            RadiusProviderScopeField.SubscriptionId =>
                providers?.Azure?.SubscriptionId ?? throw MissingProviderReference("Azure", "WithAzureProvider"),
            RadiusProviderScopeField.ResourceGroup =>
                providers?.Azure?.ResourceGroup ?? throw MissingProviderReference("Azure", "WithAzureProvider"),
            _ => throw new NotSupportedException($"Unknown provider scope field '{reference.Field}'."),
        };
    }

    private InvalidOperationException MissingProviderReference(string cloud, string configureMethod) =>
        new($"A recipe parameter on Radius environment '{_environment.Name}' references {cloud} provider " +
            $"configuration, but no {cloud} provider is configured. Call {configureMethod}(...) on the environment.");

    /// <summary>
    /// Emits a non-fatal warning for each resource-type-scoped parameter set whose resource type
    /// has no recipe entry in the emitted recipe pack.
    /// </summary>
    private void WarnUnmatchedResourceTypeScopes(IEnumerable<string> emittedResourceTypes)
    {
        var annotation = _environment.Annotations
            .OfType<Annotations.RadiusRecipeParametersAnnotation>()

View on GitHub (pinned to 25830f84bd)