OrchardCMS/OrchardCore · error · InvalidOperationException
The 'RetrieveContentTask' failed to evaluate the…
Error message
The 'RetrieveContentTask' failed to evaluate the 'ContentItemId'.
What it means
RetrieveContentTask evaluates a ContentItemId expression and throws InvalidOperationException when it cannot produce a value. This means the configured expression (e.g. a workflow variable or Liquid/JS expression) evaluated to null or empty. The workflow activity refuses to proceed without a target content item ID.
Solutions
- Open the workflow definition and set a valid ContentItemId expression on the RetrieveContentTask activity.
- Verify the referenced workflow variable exists and is populated by an earlier activity (e.g. ContentCreatedEvent output).
- Test the expression in isolation (e.g. a Code/Log task printing the value) to confirm it resolves.
- Wrap the workflow path so the task only runs when the variable is set, or use a different event providing a content item.
Example fix
// before (activity property)
ContentItemId: "" // blank or typo'd variable
// after
ContentItemId: "{{ Workflow.Input.ContentItem.ContentItemId }}" Defensive patterns
Strategy: validation
Validate before calling
// Before the workflow task runs, in a preceding condition/code activity:
var id = (string)workflowContext.Input.GetValue("ContentItemId") ?? (string?)workflowContext.GetProperty("ContentItemId");
if (string.IsNullOrWhiteSpace(id)) throw new InvalidOperationException("RetrieveContentTask: ContentItemId must be set before execution."); Try / catch
try { await task.ExecuteAsync(workflowContext, activityContext); }
catch (InvalidOperationException ex) when (ex.Message.Contains("failed to evaluate the 'ContentItemId'"))
{
logger.LogWarning(ex, "ContentItemId expression unresolved; skipping retrieve step.");
} Prevention
- Always populate the ContentItemId expression in the workflow designer.
- Reference event outputs (ContentItem.ContentItemId) rather than hand-typed IDs.
- Test the expression with a Log/Notify task before the retrieve.
- Name workflow variables consistently and avoid case typos.
When it happens
Trigger: GetContentItemIdAsync(workflowContext) returns null because the 'ContentItemId' expression property of the activity is empty, references a non-existent workflow variable, or the expression evaluates to null at runtime.
Common situations: Workflow designer misconfiguration: the ContentItemId field was left blank, a preceding task that sets the variable didn't run, or the variable name is misspelled (case-sensitive).
Understand the failure class
Background: "missing required argument" and "the following required arguments were not provided": what required-argument errors mean and how to fix them — this error's family across 20 libraries.
Related errors
- The 'UnpublishContentTask' failed to retrieve the content…
- The UpdateContentTask failed to evaluate the…
- The 'UpdateContentTask' failed to retrieve the content item.
- The 'RetrieveContentTask' failed to retrieve the content…
- The 'UnpublishContentTask' can't unpublish the content item…
AI-assisted analysis of OrchardCMS/OrchardCore@4306c0717f (2026-09-13).
Data as JSON: /api/errors/9c78783edc1a05ca.
Report an issue: GitHub.
Appendix: source
Thrown at src/OrchardCore.Modules/OrchardCore.Contents/Workflows/Activities/RetrieveContentTask.cs:33
IWorkflowScriptEvaluator scriptEvaluator,
IStringLocalizer<RetrieveContentTask> localizer)
: base(contentManager, scriptEvaluator, localizer)
{
}
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)