{"record":{"id":"29464dab53d86089","repo":"microsoft/aspire","slug":"could-not-resolve-the-azure-subscription-selected-for","errorCode":null,"errorMessage":"Could not resolve the Azure subscription selected for deployment. Ensure Azure provisioning has completed, or set the Azure:SubscriptionId configuration value.","messagePattern":"Could not resolve the Azure subscription selected for deployment\\. Ensure Azure provisioning has completed, or set the Azure:SubscriptionId configuration value\\.","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/Aspire.Hosting.Azure.Kubernetes/AzureKubernetesEnvironmentResource.AksPipeline.cs","lineNumber":849,"sourceCode":"        var resourceGroup = await ResolveScopeValueAsync(scopedResourceGroup, cancellationToken).ConfigureAwait(false);\n\n        // Fully pinned by the resource, so the global deployment state is irrelevant and must not be\n        // required. This matters because the app's own subscription may legitimately be absent when\n        // every Azure resource is an adopted existing one.\n        if (!string.IsNullOrEmpty(subscriptionId) && !string.IsNullOrEmpty(resourceGroup))\n        {\n            return (subscriptionId, resourceGroup);\n        }\n\n        var (globalSubscriptionId, globalResourceGroup) =\n            await TryGetAzureDeploymentStateAsync(services, cancellationToken).ConfigureAwait(false);\n\n        var pinnedSubscription = !string.IsNullOrEmpty(subscriptionId);\n        subscriptionId = pinnedSubscription ? subscriptionId : globalSubscriptionId;\n\n        if (string.IsNullOrEmpty(subscriptionId))\n        {\n            throw new InvalidOperationException(\n                \"Could not resolve the Azure subscription selected for deployment. \" +\n                \"Ensure Azure provisioning has completed, or set the Azure:SubscriptionId configuration value.\");\n        }\n\n        if (string.IsNullOrEmpty(resourceGroup))\n        {\n            // The saved resource group only names a group inside the saved subscription. Inheriting it\n            // across a subscription boundary would point at a group that may not exist there, or worse\n            // at an unrelated group that happens to share the name, so force discovery instead.\n            resourceGroup = pinnedSubscription && !string.Equals(subscriptionId, globalSubscriptionId, StringComparison.OrdinalIgnoreCase)\n                ? null\n                : globalResourceGroup;\n        }\n\n        return (subscriptionId, resourceGroup);\n    }\n\n    /// <summary>","sourceCodeStart":831,"sourceCodeEnd":867,"githubUrl":"https://github.com/microsoft/aspire/blob/25830f84bd145686607ad00c057b3f84e2e51d43/src/Aspire.Hosting.Azure.Kubernetes/AzureKubernetesEnvironmentResource.AksPipeline.cs#L831-L867","documentation":"During AKS deployment-scope resolution, the pipeline needs a subscription ID to run az commands (get-credentials / list resource groups). It takes the value from the pipeline argument if pinned, otherwise falls back to the persisted global Azure deployment state. If both are empty, the Azure environment has never been provisioned (so no subscription was persisted) and no Azure:SubscriptionId config was supplied, so Aspire cannot determine which subscription to operate against.","triggerScenarios":"Running `aspire deploy`/`destroy` for an AzureKubernetesEnvironmentResource when: (1) Azure provisioning has not completed (no persisted deployment state at Azure:Deployments:...), (2) globalSubscriptionId is empty because the AzureEnvironmentResource step was skipped or state was cleared, and (3) no 'Azure:SubscriptionId' configuration value was provided.","commonSituations":"Fresh CI environment with no prior deploy state; user deleted or reset the deployment state store; running destroy against an environment never deployed with this pipeline; forgetting to pass --subscription or the Azure:SubscriptionId config key in headless/CI runs.","solutions":["Set the Azure:SubscriptionId configuration value (config file, environment variable Azure__SubscriptionId, or pipeline parameter) to the subscription hosting the AKS cluster.","Run `aspire deploy` (Azure provisioning) first so the subscription is persisted in deployment state before running AKS credential acquisition or destroy.","Verify the deployment state store (Azure:Deployments section) exists and was not deleted between runs.","If running destroy on a never-deployed environment, supply the subscription explicitly since no state exists to fall back on."],"exampleFix":"// before (no subscription anywhere)\naspire deploy\n\n// after\naspire deploy --subscription 00000000-0000-0000-0000-000000000000\n// or config:\n// { \"Azure\": { \"SubscriptionId\": \"00000000-0000-0000-0000-000000000000\" } }","handlingStrategy":"validation","validationCode":"var subId = config[\"Azure:SubscriptionId\"];\nif (string.IsNullOrWhiteSpace(subId))\n    throw new InvalidOperationException(\"Set Azure:SubscriptionId or run aspire deploy first so provisioning state is persisted.\");","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Always set Azure:SubscriptionId in CI/headless environments","Run aspire deploy before any destroy or credential-consuming operation","Never delete the deployment state store between related commands"],"tags":["azure","aks","subscription","configuration"],"backgroundTag":"missing-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"}