{"record":{"id":"43a5b5cfbaf6233f","repo":"microsoft/aspire","slug":"no-active-cached-azure-deployment-was-found-for-resource","errorCode":null,"errorMessage":"No active cached Azure deployment was found for resource '{resourceName}'.","messagePattern":"No active cached Azure deployment was found for resource '(.+?)'\\.","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"src/Aspire.Hosting.Azure/AzureProvisioningController.cs","lineNumber":2828,"sourceCode":"            }\n\n            if (canceledDeploymentIds.Add(deploymentId))\n            {\n                // Multiple Aspire resources can share one ARM deployment. Track IDs so a resource\n                // tree cancellation sends at most one cancel request per deployment.\n                await CancelCachedDeploymentAsync(deploymentId, loggerService.GetLogger(resource.AzureResource), cancellationToken).ConfigureAwait(false);\n            }\n\n            await MarkCachedDeploymentCanceledAsync(\n                $\"Azure:Deployments:{bicepResource.Name}\",\n                deploymentId,\n                cancellationToken).ConfigureAwait(false);\n        }\n\n        if (requireDeployment && canceledDeploymentIds.Count == 0)\n        {\n            var resourceName = requiredDeploymentResourceName ?? (targetResources.Count == 1 ? targetResources.Single().Resource.Name : string.Join(\", \", targetResources.Select(static resource => resource.Resource.Name)));\n            throw new InvalidOperationException($\"No active cached Azure deployment was found for resource '{resourceName}'.\");\n        }\n\n        return canceledDeploymentIds.Count;\n    }\n\n    private async Task MarkCachedDeploymentCanceledAsync(string sectionName, string deploymentId, CancellationToken cancellationToken)\n    {\n        const int maxAttempts = 3;\n        for (var attempt = 0; attempt < maxAttempts; attempt++)\n        {\n            var section = await deploymentStateManager.AcquireSectionAsync(sectionName, cancellationToken).ConfigureAwait(false);\n            if (TryGetCachedDeploymentId(section) is not { } currentDeploymentId ||\n                !StringComparers.AzureResourceId.Equals(currentDeploymentId, deploymentId) ||\n                !IsActiveCachedDeployment(section))\n            {\n                return;\n            }\n","sourceCodeStart":2810,"sourceCodeEnd":2846,"githubUrl":"https://github.com/microsoft/aspire/blob/25830f84bd145686607ad00c057b3f84e2e51d43/src/Aspire.Hosting.Azure/AzureProvisioningController.cs#L2810-L2846","documentation":"Thrown when an operation requires an active cached Azure deployment (requireDeployment) but no deployment IDs were found in the cache for the target resource(s). Cancel/deployment-targeting operations act on cached deployment records; with none present the operation cannot proceed.","triggerScenarios":"Calling a deployment-dependent intent (e.g. cancel deployment / redeploy) where canceledDeploymentIds.Count == 0 and requiredDeploymentResourceName is set, or multiple/single target resources are resolved to compute a name for the message.","commonSituations":"Cancelling a deployment for a resource that was never deployed from this state store; running after state was forgotten or the cache was cleared; pointing the operation at a different environment/state directory than the one used to deploy.","solutions":["Deploy the resource first so an active deployment is cached, then retry the operation.","Confirm you are operating against the same deployment state store used for the original deployment.","If the deployment is gone anyway, use ForgetState to reset local state rather than cancel.","Verify the target resource name(s) match resources with active deployments."],"exampleFix":null,"handlingStrategy":"validation","validationCode":"// confirm an active deployment exists before cancel-style operations\nif (!provisioningState.HasActiveDeployment(resourceName))\n{\n    logger.LogInformation(\"No active deployment for {Resource}; nothing to cancel\", resourceName);\n    return;\n}","typeGuard":null,"tryCatchPattern":"try { await controller.CancelDeploymentAsync(resourceName); }\ncatch (InvalidOperationException ex) when (ex.Message.Contains(\"No active cached Azure deployment\"))\n{\n    logger.LogWarning(\"No cached deployment for {Resource}; nothing to cancel\", resourceName);\n}","preventionTips":["Only issue deployment-dependent operations against resources deployed from the same state store.","After clearing/forgetting state, re-deploy before attempting deployment-scoped operations.","Match the state directory/environment used at deploy time.","Check the resource list/status for active deployments first."],"tags":["azure","provisioning","deployment","state"],"backgroundTag":"record-not-found","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"}