{"record":{"id":"fa606e5d9d960121","repo":"microsoft/aspire","slug":"deployment-failed-errormessage","errorCode":null,"errorMessage":"Deployment failed: {errorMessage}","messagePattern":"Deployment failed: (.+?)","errorType":"exception","errorClass":"ProvisioningFailedException","httpStatus":null,"severity":"critical","filePath":"src/Aspire.Hosting.Azure/AzureBicepResource.cs","lineNumber":387,"sourceCode":"                        new MarkdownString($\"Successfully provisioned **{resource.Name}**\"),\n                        CompletionState.Completed,\n                        context.CancellationToken).ConfigureAwait(false);\n                }\n            }\n            catch (Exception ex)\n            {\n                var errorMessage = ex switch\n                {\n                    RequestFailedException requestEx =>\n                        $\"Deployment failed: {ExtractDetailedErrorMessage(requestEx)}\",\n                    _ => $\"Deployment failed: {ex.Message}\"\n                };\n                resource.ProvisioningTaskCompletionSource?.TrySetException(ex);\n                await resourceTask.CompleteAsync(\n                    new MarkdownString($\"Failed to provision **{resource.Name}**: {errorMessage}\"),\n                    CompletionState.CompletedWithError,\n                    context.CancellationToken).ConfigureAwait(false);\n                throw new ProvisioningFailedException(errorMessage, ex);\n            }\n        }\n    }\n\n    /// <summary>\n    /// Extracts detailed error information from Azure RequestFailedException responses.\n    /// Parses the following JSON error structures:\n    /// 1. Standard Azure error format: { \"error\": { \"code\": \"...\", \"message\": \"...\", \"details\": [...] } }\n    /// 2. Deployment-specific error format: { \"properties\": { \"error\": { \"code\": \"...\", \"message\": \"...\" } } }\n    /// 3. Nested error details with recursive parsing for deeply nested error hierarchies\n    /// </summary>\n    /// <param name=\"requestEx\">The Azure RequestFailedException containing the error response</param>\n    /// <returns>The most specific error message found, or the original exception message if parsing fails</returns>\n    internal static string ExtractDetailedErrorMessage(RequestFailedException requestEx)\n        => AzureProvisioningFailureDetails.FromRequestFailedException(requestEx).ToDetailedMessage();\n\n    /// <summary>\n    /// Known parameters that will be filled in automatically by the host environment.","sourceCodeStart":369,"sourceCodeEnd":405,"githubUrl":"https://github.com/microsoft/aspire/blob/25830f84bd145686607ad00c057b3f84e2e51d43/src/Aspire.Hosting.Azure/AzureBicepResource.cs#L369-L405","documentation":"When provisioning a Bicep resource fails with an Azure RequestFailedException, ProvisionAzureBicepResourceAsync extracts a detailed error message from the response, reports it to the provisioning task, and rethrows it as a ProvisioningFailedException with message 'Deployment failed: {errorMessage}'.","triggerScenarios":"The underlying Azure ARM deployment request fails during provisionStep: invalid template (ARM template validation error), resource-name conflicts, quota exceeded, missing permissions, invalid parameters, or resource provider not registered.","commonSituations":"Wrong subscription/resource group permissions on the signed-in identity; bicep parameter type mismatches; name collisions with existing resources; region unavailability; unregistered resource providers on the subscription.","solutions":["Read the embedded errorMessage (extracted from the RequestFailedException detail) for the exact ARM error code.","Fix template/parameter issues flagged by the message (validation errors, invalid values).","Check the identity's RBAC role on the target resource group and Azure CLI login state.","Resolve name conflicts or quota/region issues, and register missing resource providers."],"exampleFix":"try\n{\n    await provisioner.ProvisionAsync(...);\n}\ncatch (ProvisioningFailedException ex)\n{\n    logger.LogError(ex, \"Bicep deployment failed: {Message}\", ex.Message); // message carries ARM detail\n    throw;\n}","handlingStrategy":"try-catch","validationCode":"// Pre-flight: verify login & resource group access before deployment\nvar rgExists = await armClient.GetResourceGroups().ExistsAsync(rgName);\nif (!rgExists) throw new InvalidOperationException($\"Resource group '{rgName}' does not exist or is not accessible.\");","typeGuard":null,"tryCatchPattern":"try { await provisioningPipeline.RunAsync(ct); }\ncatch (ProvisioningFailedException ex)\n{\n    // ex.Message embeds the ARM error detail extracted from RequestFailedException\n    logger.LogError(ex, \"Azure deployment failed\");\n    throw;\n}","preventionTips":["Ensure the signed-in identity has Contributor on the target resource group.","Validate templates/parameters with az bicep build / what-if before deploy.","Use unique resource names to avoid collisions.","Register required resource providers on the subscription.","Retry transient ARM errors (429/5xx) with backoff."],"tags":["azure","bicep","provisioning","arm","deployment"],"backgroundTag":"api-error-response","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"}