{"record":{"id":"b0fef3ca6423ea2e","repo":"microsoft/aspire","slug":"azure-deployment-for-resource-name-was-canceled","errorCode":null,"errorMessage":"Azure deployment for {resource.Name} was canceled.","messagePattern":"Azure deployment for (.+?) was canceled\\.","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"src/Aspire.Hosting.Azure/Provisioning/Provisioners/BicepProvisioner.cs","lineNumber":424,"sourceCode":"        {\n            // Successful adoption replays the deployment outputs into the resource\n            // state exactly as normal provisioning would.\n            return await ConfigureSucceededReconciledDeploymentAsync(\n                resource,\n                stateSection,\n                deploymentId,\n                deployment.Outputs,\n                currentLocation,\n                cancellationToken).ConfigureAwait(false);\n        }\n\n        if (string.Equals(deployment.ProvisioningState, DeploymentStateProvisioningStateCanceled, StringComparisons.AzureProvisioningState))\n        {\n            // Preserve ARM's terminal cancellation so the dashboard explains why this\n            // resource stopped instead of silently retrying.\n            await PersistReconciledProvisioningStateAsync(stateSection, DeploymentStateProvisioningStateCanceled, cancellationToken).ConfigureAwait(false);\n            await PublishReconciledTerminalStateAsync(resource, AzureProvisioningStrings.ResourceStateAzureDeploymentCanceled).ConfigureAwait(false);\n            throw new InvalidOperationException($\"Azure deployment for {resource.Name} was canceled.\");\n        }\n\n        if (string.Equals(deployment.ProvisioningState, DeploymentStateProvisioningStateFailed, StringComparisons.AzureProvisioningState))\n        {\n            // Preserve ARM's terminal failure for the same reason as cancellation:\n            // this is the outcome of the adopted deployment.\n            await PersistReconciledProvisioningStateAsync(stateSection, DeploymentStateProvisioningStateFailed, cancellationToken).ConfigureAwait(false);\n            await PublishReconciledTerminalStateAsync(resource, AzureProvisioningStrings.ResourceStateAzureDeploymentFailed).ConfigureAwait(false);\n            throw new InvalidOperationException($\"Azure deployment for {resource.Name} failed.\");\n        }\n\n        return false;\n    }\n\n    private async Task PersistReconciledProvisioningStateAsync(DeploymentStateSection stateSection, string provisioningState, CancellationToken cancellationToken)\n    {\n        stateSection.Data[DeploymentStateProvisioningStateKey] = provisioningState;\n        await deploymentStateManager.SaveSectionAsync(stateSection, cancellationToken).ConfigureAwait(false);","sourceCodeStart":406,"sourceCodeEnd":442,"githubUrl":"https://github.com/microsoft/aspire/blob/25830f84bd145686607ad00c057b3f84e2e51d43/src/Aspire.Hosting.Azure/Provisioning/Provisioners/BicepProvisioner.cs#L406-L442","documentation":"When reconciling a Bicep deployment, Aspire reads the ARM deployment's ProvisioningState. If ARM reports the deployment was Canceled, Aspire persists that terminal state, publishes an 'Azure deployment canceled' state to the dashboard, and throws InvalidOperationException so the resource does not silently re-enter a retry loop. This makes ARM's terminal cancellation visible instead of looping indefinitely.","triggerScenarios":"Calling GetOrCreateResourceAsync / ReconcileDeploymentStateAsync (or TryAdoptActiveDeploymentConflictAsync when adopting an existing active deployment) against a deployment whose latest ARM provisioning state is 'Canceled' — typically because someone or another process canceled the deployment in the Azure portal, or a Ctrl+C/timeout canceled it mid-provisioning.","commonSituations":"A developer canceled a deployment in the Azure portal or via CLI; an upstream ARM timeout or parallel conflicting deployment caused cancellation; a previous run of the app host was terminated and its deployment canceled, and a new run now reconciles against that canceled deployment.","solutions":["Check the deployment in the Azure portal (Resource Group > Deployments) to see which operation was canceled and why.","Delete or clean up the canceled deployment / resource group state, then re-run the app host so a fresh deployment is created.","If you canceled it intentionally (Ctrl+C during provisioning), simply re-run — but ensure no stale conflicting deployment remains.","Look for concurrent processes deploying to the same resource group and serialize them; overlapping deployments can cancel each other.","If cancellation is spurious, inspect activity logs for the caller that issued the cancel request."],"exampleFix":"// before\ndotnet run --project MyAspireApp.AppHost   # repeatedly hits canceled deployment\n\n// after\naz group deployment list -g my-rg -o table          # find the canceled deployment\naz deployment group delete -g my-rg --name <stale-deployment>\ndotnet run --project MyAspireApp.AppHost             # fresh deployment succeeds","handlingStrategy":"try-catch","validationCode":"var deployment = await armClient.GetArmResource(deploymentId).GetAsync(ct);\nif (string.Equals(deployment.Value.Data.ProvisioningState, \"Canceled\", StringComparison.OrdinalIgnoreCase))\n{\n    // reconcile stale deployment state before re-running provisioning\n}","typeGuard":null,"tryCatchPattern":"try\n{\n    await provisioner.GetOrCreateResourceAsync(resource, context, ct);\n}\ncatch (InvalidOperationException ex) when (ex.Message.Contains(\"was canceled\"))\n{\n    logger.LogWarning(ex, \"Azure deployment was canceled (ARM terminal state). Check portal deployments, clean up, and re-run.\");\n}","preventionTips":["Don't cancel deployments mid-run (avoid killing the AppHost during active provisioning; stop it gracefully).","Check Resource Group > Deployments in the portal before re-running to spot stale canceled deployments.","Avoid running multiple app hosts / pipelines deploying to the same resource group concurrently.","Treat the dashboard's 'Azure deployment canceled' state as terminal and investigate before retrying."],"tags":["azure","bicep","deployment","canceled","arm"],"backgroundTag":"deployment-canceled","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"}