{"record":{"id":"5ae02aad9afe22f1","repo":"microsoft/aspire","slug":"azure-deployment-for-resource-name-failed","errorCode":null,"errorMessage":"Azure deployment for {resource.Name} failed.","messagePattern":"Azure deployment for (.+?) failed\\.","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"src/Aspire.Hosting.Azure/Provisioning/Provisioners/BicepProvisioner.cs","lineNumber":433,"sourceCode":"                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);\n    }\n\n    private async Task PublishReconciledTerminalStateAsync(AzureBicepResource resource, string state)\n    {\n        await notificationService.PublishUpdateAsync(resource, snapshot => snapshot with\n        {\n            State = new(state, KnownResourceStateStyles.Error)\n        }).ConfigureAwait(false);\n    }","sourceCodeStart":415,"sourceCodeEnd":451,"githubUrl":"https://github.com/microsoft/aspire/blob/25830f84bd145686607ad00c057b3f84e2e51d43/src/Aspire.Hosting.Azure/Provisioning/Provisioners/BicepProvisioner.cs#L415-L451","documentation":"When reconciling a Bicep deployment, Aspire reads the ARM deployment's ProvisioningState. If ARM reports the deployment Failed, Aspire persists that terminal failure state, publishes an 'Azure deployment failed' state to the dashboard, and throws InvalidOperationException so the failure surfaces immediately instead of being silently retried. This preserves ARM's authoritative failure outcome for the adopted/reconciled deployment.","triggerScenarios":"Calling GetOrCreateResourceAsync / ReconcileDeploymentStateAsync (or TryAdoptActiveDeploymentConflictAsync while adopting an active conflicting deployment) against a deployment whose latest ARM provisioning state is 'Failed' — e.g. the Bicep template was rejected by ARM, a nested resource failed, quota/RP registration errors, or a prior run's deployment already failed.","commonSituations":"Invalid Bicep parameters or template errors; resource name conflicts or quota exceeded in the region; a resource provider not registered on the subscription; re-running the app host against a resource group whose previous deployment failed.","solutions":["Open the Azure portal (Resource Group > Deployments > failed deployment > Error details) or run az deployment group show to read the ARM error code and message.","Fix the underlying template/parameter/quota/RP-registration error reported by ARM, then re-run the app host.","Register any missing resource providers (az provider register --namespace <ns>) or request a quota increase if the error says so.","Delete the failed deployment and any partially created resources, then re-run to start a clean deployment.","Validate the Bicep locally before deploying (az bicep build / what-if) to catch template errors early."],"exampleFix":"// before\n# failed: ProviderRegistration \"Microsoft.App\" missing\naz deployment group show -g my-rg -n <failed-deployment> --query properties.error\n\n// after\naz provider register --namespace Microsoft.App\naz provider show -n Microsoft.App --query registrationState   # wait for Registered\n# re-run the AppHost so the deployment retries cleanly","handlingStrategy":"try-catch","validationCode":"var deployment = await armClient.GetArmResource(deploymentId).GetAsync(ct);\nif (string.Equals(deployment.Value.Data.ProvisioningState, \"Failed\", StringComparison.OrdinalIgnoreCase))\n{\n    var error = deployment.Value.Data.Error; // inspect before re-attempting\n}","typeGuard":null,"tryCatchPattern":"try\n{\n    await provisioner.GetOrCreateResourceAsync(resource, context, ct);\n}\ncatch (InvalidOperationException ex) when (ex.Message.Contains(\"failed\"))\n{\n    logger.LogError(ex, \"Azure deployment failed (ARM terminal state). Inspect deployment error details in the portal.\");\n}","preventionTips":["Validate Bicep templates with az bicep build / az deployment group what-if before running the AppHost.","Verify the subscription has quota and all referenced resource providers registered before provisioning.","Read the failed deployment's error details in the portal or via az deployment group show and fix the root ARM error, not just the symptom.","Clean up partially created resources from failed deployments to avoid cascading name/lock conflicts."],"tags":["azure","bicep","deployment","failed","arm"],"backgroundTag":"deployment-failed","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"}