{"record":{"id":"1a32db86f176782e","repo":"microsoft/aspire","slug":"changing-the-location-of-azure-resource-0-requires-deleting","errorCode":null,"errorMessage":"Changing the location of Azure resource '{0}' requires deleting and recreating it. Any data in the deleted resource may be permanently lost. Set the '{1}' command argument to true to continue.","messagePattern":"Changing the location of Azure resource '(.+?)' requires deleting and recreating it\\. Any data in the deleted resource may be permanently lost\\. Set the '(.+?)' command argument to true to continue\\.","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"src/Aspire.Hosting.Azure/AzureProvisioningController.cs","lineNumber":3458,"sourceCode":"            return null;\n        }\n\n        var armClientProvider = serviceProvider.GetRequiredService<IArmClientProvider>();\n        var tokenCredentialProvider = serviceProvider.GetRequiredService<ITokenCredentialProvider>();\n        var armClient = armClientProvider.GetArmClient(tokenCredentialProvider.TokenCredential, context.SubscriptionId);\n        if (!await armClient.ResourceExistsAsync(resourceId, cancellationToken).ConfigureAwait(false))\n        {\n            // Cached state can point at a resource that has already been manually deleted. In that\n            // case the location change only needs to update local override state and reprovision.\n            return null;\n        }\n\n        if (!confirmDelete)\n        {\n            // Resource command confirmations are UI metadata and are not enforced by non-interactive\n            // CLI or MCP callers. Require an explicit command argument before publishing transient\n            // state or reaching the destructive boundary.\n            throw new InvalidOperationException(FormatUserString(\n                AzureProvisioningStrings.ChangeResourceLocationDeleteConfirmationRequiredFormat,\n                resource.Name,\n                ConfirmDeleteArgumentName));\n        }\n\n        return new(armClient, resourceId, currentLocation);\n    }\n\n    private async Task DeleteCachedResourceForLocationChangeAsync(\n        AzureBicepResource resource,\n        string requestedLocation,\n        LocationChangeResourceDeletion? resourceDeletion,\n        CancellationToken cancellationToken)\n    {\n        if (resourceDeletion is null)\n        {\n            return;\n        }","sourceCodeStart":3440,"sourceCodeEnd":3476,"githubUrl":"https://github.com/microsoft/aspire/blob/25830f84bd145686607ad00c057b3f84e2e51d43/src/Aspire.Hosting.Azure/AzureProvisioningController.cs#L3440-L3476","documentation":"Thrown when a change-location operation on an Azure resource would require deleting and recreating the resource, but the user has not explicitly confirmed the destructive action. Because command confirmations are UI metadata not enforced for non-interactive CLI/MCP callers, the controller requires an explicit ConfirmDelete command argument set to true before proceeding.","triggerScenarios":"Invoking the change-resource-location command where the target's current location differs from the effective location and the ConfirmDeleteArgumentName command argument is absent or not true (confirmDelete == false).","commonSituations":"Moving a resource to another Azure region via CLI/MCP automation without passing the confirmation argument; relying on the dashboard confirmation checkbox that non-interactive callers bypass; forgetting the argument after a script refactor.","solutions":["Pass the ConfirmDelete command argument as true (e.g. --ConfirmDelete true) on the change-location command after acknowledging data loss.","Back up/export any data in the resource before confirming, since deletion may permanently destroy it.","If data preservation is impossible (e.g. location-bound data), plan recreation and re-provisioning of dependent resources.","For interactive flows, complete the dashboard/CLI confirmation prompt instead of bypassing it."],"exampleFix":"// before\naspire publish --operation change-location --resource mydb --location westus\n// after\naspire publish --operation change-location --resource mydb --location westus --ConfirmDelete true","handlingStrategy":"validation","validationCode":"// supply the confirmation argument when the location actually changes\nvar args = currentLocation != targetLocation\n    ? new Dictionary<string, object?> { [\"ConfirmDelete\"] = true }\n    : new Dictionary<string, object?>();","typeGuard":null,"tryCatchPattern":"try { await controller.ChangeLocationAsync(resource, newLocation, args); }\ncatch (InvalidOperationException ex) when (ex.Message.Contains(\"requires deleting and recreating\"))\n{\n    // surface a confirmation prompt; re-invoke with ConfirmDelete=true on acceptance\n}","preventionTips":["Never rely on dashboard confirmation metadata for CLI/MCP automation — pass the explicit argument.","Back up resource data before any location change.","Detect location changes up front and ask the user for confirmation in your tooling.","Remember location changes are destructive recreations, not moves."],"tags":["azure","destructive-operation","confirmation","location"],"backgroundTag":"missing-required-flag","analyzedSha":"25830f84bd145686607ad00c057b3f84e2e51d43","analyzedAt":"2026-09-16T11:10:06.193Z","contentChangedAt":"2026-09-16T11:10:06.193Z","schemaVersion":2},"datasetVersion":"2026-09-21T09:17:21.228Z"}