microsoft/aspire · error · InvalidOperationException
No active cached Azure deployment was found for resource
Error message
No active cached Azure deployment was found for resource '{resourceName}'. What it means
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.
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.
Defensive patterns
Strategy: validation
Validate before calling
// confirm an active deployment exists before cancel-style operations
if (!provisioningState.HasActiveDeployment(resourceName))
{
logger.LogInformation("No active deployment for {Resource}; nothing to cancel", resourceName);
return;
} Try / catch
try { await controller.CancelDeploymentAsync(resourceName); }
catch (InvalidOperationException ex) when (ex.Message.Contains("No active cached Azure deployment"))
{
logger.LogWarning("No cached deployment for {Resource}; nothing to cancel", resourceName);
} Prevention
- 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.
When it happens
Trigger: 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.
Common situations: 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.
Understand the failure class
Background: Record Not Found Errors: "not found", RecordNotFound, and "was not found" — what they mean and how to fix them — this error's family across 28 libraries.
Related errors
- Deployment failed
- No cached Azure resource IDs were found for resource
- Project ' ' does not have a valid endpoint.
- A of type cannot be assigned to a BicepValue< >.
- An azure location/region is required. Set the…
AI-assisted analysis of microsoft/aspire@25830f84bd (2026-09-16).
Data as JSON: /api/errors/43a5b5cfbaf6233f.
Report an issue: GitHub.
Appendix: source
Thrown at src/Aspire.Hosting.Azure/AzureProvisioningController.cs:2828
}
if (canceledDeploymentIds.Add(deploymentId))
{
// Multiple Aspire resources can share one ARM deployment. Track IDs so a resource
// tree cancellation sends at most one cancel request per deployment.
await CancelCachedDeploymentAsync(deploymentId, loggerService.GetLogger(resource.AzureResource), cancellationToken).ConfigureAwait(false);
}
await MarkCachedDeploymentCanceledAsync(
$"Azure:Deployments:{bicepResource.Name}",
deploymentId,
cancellationToken).ConfigureAwait(false);
}
if (requireDeployment && canceledDeploymentIds.Count == 0)
{
var resourceName = requiredDeploymentResourceName ?? (targetResources.Count == 1 ? targetResources.Single().Resource.Name : string.Join(", ", targetResources.Select(static resource => resource.Resource.Name)));
throw new InvalidOperationException($"No active cached Azure deployment was found for resource '{resourceName}'.");
}
return canceledDeploymentIds.Count;
}
private async Task MarkCachedDeploymentCanceledAsync(string sectionName, string deploymentId, CancellationToken cancellationToken)
{
const int maxAttempts = 3;
for (var attempt = 0; attempt < maxAttempts; attempt++)
{
var section = await deploymentStateManager.AcquireSectionAsync(sectionName, cancellationToken).ConfigureAwait(false);
if (TryGetCachedDeploymentId(section) is not { } currentDeploymentId ||
!StringComparers.AzureResourceId.Equals(currentDeploymentId, deploymentId) ||
!IsActiveCachedDeployment(section))
{
return;
}
View on GitHub (pinned to 25830f84bd)