microsoft/aspire · error · MissingConfigurationException

An azure location/region is required. Set the…

Error message

An azure location/region is required. Set the Azure:Location configuration value.

What it means

After resolving the subscription, CreateProvisioningContextAsync requires a default location/region in which resources will be deployed. When options.Location is null or empty it throws MissingConfigurationException directing you to set the Azure:Location configuration value.

Solutions

  1. Add "Azure": { "Location": "westus2" } to appsettings.json or user secrets of the AppHost.
  2. Set the AZURE_LOCATION / Azure__Location environment variable before provisioning.
  3. Run through `azd provision`/`azd up`, which supplies the location from the azure.yaml environment.
  4. Or set options.Location programmatically in the provisioning options configuration.

Example fix

// before
dotnet run --project AppHost
// after
AZURE_LOCATION=westus2 dotnet run --project AppHost
Defensive patterns

Strategy: validation

Validate before calling

var location = configuration["Azure:Location"];
if (string.IsNullOrEmpty(location))
{
    throw new InvalidOperationException("Set Azure:Location (appsettings or AZURE_LOCATION env var) before provisioning.");
}

Try / catch

try { await provider.CreateProvisioningContextAsync(ct); } catch (MissingConfigurationException ex) when (ex.Message.Contains("location")) { /* configure Azure:Location and retry */ }

Prevention

When it happens

Trigger: Provisioning Azure resources with no Azure:Location config entry (appsettings.json, environment variable Azure__Location, or azd-picked region) and no options.Location set programmatically.

Common situations: Running the AppHost outside `azd` (azd normally injects the location); CI runs without AZURE_LOCATION set; empty-string location from a config placeholder.

Understand the failure class

Background: "X is required", "must be set", "cannot be empty": the missing-required-config error family, from Vertex AI project/location to WeChat keys — this error's family across 18 libraries.

Related errors


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

Appendix: source

Thrown at src/Aspire.Hosting.Azure/Provisioning/Internal/BaseProvisioningContextProvider.cs:111

        var subscriptionId = _options.SubscriptionId ?? throw new MissingConfigurationException("An Azure subscription id is required. Set the Azure:SubscriptionId configuration value.");

        var credential = _tokenCredentialProvider.TokenCredential;

        if (_tokenCredentialProvider is DefaultTokenCredentialProvider defaultProvider)
        {
            defaultProvider.LogCredentialType();
        }

        var armClient = _armClientProvider.GetArmClient(credential, subscriptionId);

        var (subscriptionResource, tenantResource) = await armClient.GetSubscriptionAndTenantAsync(cancellationToken).ConfigureAwait(false);

        _logger.LogInformation("Default subscription: {name} ({subscriptionId})", subscriptionResource.DisplayName, subscriptionResource.Id);
        _logger.LogInformation("Tenant: {tenantId}", tenantResource.TenantId);

        if (string.IsNullOrEmpty(_options.Location))
        {
            throw new MissingConfigurationException("An azure location/region is required. Set the Azure:Location configuration value.");
        }

        // Acquire Azure state section for reading/writing configuration
        var azureStateSection = await _deploymentStateManager.AcquireSectionAsync("Azure", cancellationToken).ConfigureAwait(false);

        string resourceGroupName;
        bool createIfAbsent;

        if (string.IsNullOrEmpty(_options.ResourceGroup))
        {
            // Generate an resource group name since none was provided
            // Create a unique resource group name and save it in deployment state
            resourceGroupName = GetDefaultResourceGroupName();

            createIfAbsent = true;

            azureStateSection.Data["ResourceGroup"] = resourceGroupName;
        }

View on GitHub (pinned to 25830f84bd)