OrchardCMS/OrchardCore · error · InvalidOperationException
The 'RetrieveContentTask' failed to retrieve the content…
Error message
The 'RetrieveContentTask' failed to retrieve the content item.
What it means
RetrieveContentTask resolved a ContentItemId but IContentManager.GetAsync(id, VersionOptions.Latest) returned null, meaning no content item with that ID exists. The library throws to abort the activity rather than operating on a missing item.
Solutions
- Verify the content item exists for the current tenant with that exact ContentItemId.
- Check that the ID expression yields the correct ID (log it before this task).
- Guard the workflow: only run this task when the content item is known to exist (e.g. triggered by a content event for that item).
- If deletion is expected, add a fallback path or use a try/catch-style error outcome in the workflow.
Example fix
// before
ContentItemId: "{{ Workflow.Input.Foo.Id }}" // wrong source
// after
ContentItemId: "{{ Workflow.Input.ContentItem.ContentItemId }}" Defensive patterns
Strategy: validation
Validate before calling
var item = await contentManager.GetAsync(id, VersionOptions.Latest);
if (item is null) throw new InvalidOperationException($"Content item '{id}' does not exist; workflow cannot retrieve it."); Try / catch
try { await task.ExecuteAsync(workflowContext, activityContext); }
catch (InvalidOperationException ex) when (ex.Message.Contains("failed to retrieve the content item"))
{
logger.LogWarning(ex, "Target content item no longer exists.");
return; // or take fallback path
} Prevention
- Confirm the referenced item exists before running the workflow (existence condition).
- Avoid hardcoding ContentItemIds across environments.
- Account for deletion race conditions with fallback handling.
- Use the content event's own item instead of separate lookups when possible.
When it happens
Trigger: The evaluated content item ID does not match any persisted content item (deleted item, wrong ID string, wrong tenant, or unpublished item removed before the workflow ran).
Common situations: Content was deleted between trigger and execution, ID was copied from another environment, or a workflow variable holds a stale/incorrect ID.
Understand the failure class
Background: "Not found" and "does not exist" errors: why "Task not found", "No such folder", and "Can't find" fire when a lookup comes back empty — this error's family across 14 libraries.
Related errors
- The 'UpdateContentTask' failed to retrieve the content item.
- The 'RetrieveContentTask' failed to evaluate the…
- The 'UnpublishContentTask' failed to retrieve the content…
- The 'UnpublishContentTask' can't unpublish the content item…
- The UpdateContentTask failed to evaluate the…
AI-assisted analysis of OrchardCMS/OrchardCore@4306c0717f (2026-09-13).
Data as JSON: /api/errors/9e83816536bf7319.
Report an issue: GitHub.
Appendix: source
Thrown at src/OrchardCore.Modules/OrchardCore.Contents/Workflows/Activities/RetrieveContentTask.cs:36
{
}
public override string Name => nameof(RetrieveContentTask);
public override LocalizedString DisplayText => S["Retrieve Content Task"];
public override LocalizedString Category => S["Content"];
public override IEnumerable<Outcome> GetPossibleOutcomes(WorkflowExecutionContext workflowContext, ActivityContext activityContext)
=> Outcome(S["Retrieved"]);
public override async Task<ActivityExecutionResult> ExecuteAsync(WorkflowExecutionContext workflowContext, ActivityContext activityContext)
{
var contentItemId = (await GetContentItemIdAsync(workflowContext))
?? throw new InvalidOperationException($"The '{nameof(RetrieveContentTask)}' failed to evaluate the 'ContentItemId'.");
var contentItem = (await ContentManager.GetAsync(contentItemId, VersionOptions.Latest))
?? throw new InvalidOperationException($"The '{nameof(RetrieveContentTask)}' failed to retrieve the content item.");
if (string.IsNullOrEmpty(workflowContext.CorrelationId))
{
workflowContext.CorrelationId = contentItem.ContentItemId;
}
workflowContext.Properties[ContentEventConstants.ContentItemInputKey] = contentItem;
workflowContext.LastResult = contentItem;
return Outcome("Retrieved");
}
}
View on GitHub (pinned to 4306c0717f)