{"record":{"id":"e8846b0452dc02e7","repo":"microsoft/aspire","slug":"azure-resources-cannot-be-managed-because-the-azure","errorCode":null,"errorMessage":"Azure resources cannot be managed because the Azure subscription ID is missing or invalid.","messagePattern":"Azure resources cannot be managed because the Azure subscription ID is missing or invalid\\.","errorType":"exception","errorClass":"MissingConfigurationException","httpStatus":null,"severity":"error","filePath":"src/Aspire.Hosting.Azure/AzureProvisioningController.cs","lineNumber":3083,"sourceCode":"    private async Task<IArmClient> GetArmClientForResourceIdAsync(string resourceId, CancellationToken cancellationToken)\n    {\n        string? subscriptionId = null;\n        if (ResourceIdentifier.TryParse(resourceId, out var parsedResourceId) &&\n            parsedResourceId is not null)\n        {\n            // Prefer the subscription embedded in the ARM resource ID. This makes cleanup resilient\n            // after the user changes Azure context but still has cached state for old resources.\n            subscriptionId = parsedResourceId.SubscriptionId;\n        }\n\n        if (string.IsNullOrWhiteSpace(subscriptionId))\n        {\n            subscriptionId = (await GetCurrentAzureContextAsync(cancellationToken).ConfigureAwait(false)).SubscriptionId;\n        }\n\n        if (!Guid.TryParse(subscriptionId, out _))\n        {\n            throw new MissingConfigurationException(\"Azure resources cannot be managed because the Azure subscription ID is missing or invalid.\");\n        }\n\n        var armClientProvider = serviceProvider.GetRequiredService<IArmClientProvider>();\n        var tokenCredentialProvider = serviceProvider.GetRequiredService<ITokenCredentialProvider>();\n        return armClientProvider.GetArmClient(tokenCredentialProvider.TokenCredential, subscriptionId);\n    }\n\n    private static string? TryGetCachedDeploymentId(DeploymentStateSection section)\n        => section.Data[\"Id\"]?.GetValue<string>() is { Length: > 0 } deploymentId ? deploymentId : null;\n\n    private static bool IsActiveCachedDeployment(DeploymentStateSection section)\n        => string.Equals(\n            section.Data[BicepProvisioner.DeploymentStateProvisioningStateKey]?.GetValue<string>(),\n            BicepProvisioner.DeploymentStateProvisioningStateRunning,\n            StringComparison.Ordinal);\n\n    private static bool IsArmDeploymentResourceId(string resourceId)\n    {","sourceCodeStart":3065,"sourceCodeEnd":3101,"githubUrl":"https://github.com/microsoft/aspire/blob/25830f84bd145686607ad00c057b3f84e2e51d43/src/Aspire.Hosting.Azure/AzureProvisioningController.cs#L3065-L3101","documentation":"Thrown when creating the ARM client because the resolved Azure subscription ID is missing or not a valid GUID. The controller resolves the subscription from configuration or the current Azure context, validates it with Guid.TryParse, and refuses to manage resources without a well-formed subscription ID.","triggerScenarios":"Calling PrepareResources/ARM client creation when the subscriptionId variable is null/empty/not a GUID — e.g. no subscription configured and GetCurrentAzureContextAsync returned a context with a missing or malformed SubscriptionId.","commonSituations":"AZURE_SUBSCRIPTION_ID env var unset or contains a display name instead of a GUID; not logged in with az login so no context; stale/corrupted local Azure context; typo in config value.","solutions":["Set the Azure subscription ID configuration (e.g. AZURE_SUBSCRIPTION_ID env var or appsettings) to a valid GUID.","Run 'az login' and 'az account set --subscription <guid>' so the current Azure context has a valid subscription.","Verify with 'az account show --query id' that the resolved subscription is a GUID and copy it exactly.","Clear and re-create the cached Azure context if it holds a stale subscription value."],"exampleFix":"// before\nset AZURE_SUBSCRIPTION_ID=My Subscription\n// after\nset AZURE_SUBSCRIPTION_ID=00000000-0000-0000-0000-000000000000","handlingStrategy":"validation","validationCode":"// validate subscription before building the ARM client\nvar sub = Environment.GetEnvironmentVariable(\"AZURE_SUBSCRIPTION_ID\")\n          ?? azureConfig.SubscriptionId;\nif (string.IsNullOrWhiteSpace(sub) || !Guid.TryParse(sub, out _))\n{\n    throw new InvalidOperationException(\n        \"Set AZURE_SUBSCRIPTION_ID to a valid subscription GUID before running.\");\n}","typeGuard":"bool HasValidSubscriptionId(string? sub) => Guid.TryParse(sub, out _);","tryCatchPattern":"try { var client = armClientProvider.GetArmClient(credential, subscriptionId); }\ncatch (MissingConfigurationException ex) when (ex.Message.Contains(\"subscription ID is missing or invalid\"))\n{\n    // prompt for/repair subscription config, then retry\n}","preventionTips":["Always set AZURE_SUBSCRIPTION_ID to the GUID, never the subscription display name.","Run 'az login' and 'az account set --subscription <guid>' before provisioning.","Validate the ID with Guid.TryParse in startup checks.","Copy the subscription ID from 'az account show --query id -o tsv'."],"tags":["azure","configuration","subscription","arm"],"backgroundTag":"invalid-config-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"}