OrchardCMS/OrchardCore · error · InvalidOperationException
The 'UnpublishContentTask' failed to retrieve the content…
Error message
The 'UnpublishContentTask' failed to retrieve the content item.
What it means
UnpublishContentTask calls GetContentAsync(workflowContext) to resolve the target content item; if it returns null the activity cannot proceed and throws InvalidOperationException. This protects against unpublishing an unresolvable target.
Solutions
- Set a valid ContentItemId or ContentItem expression on the UnpublishContentTask activity.
- Ensure an earlier activity populates the referenced workflow variable.
- When the workflow starts from a content event, rely on the event's content item input instead of a manual expression.
- Add a condition before the task to skip it when the variable is empty.
Example fix
// before
ContentItemId: ""
// after
ContentItemId: "{{ Workflow.Input.ContentItem.ContentItemId }}" Defensive patterns
Strategy: validation
Validate before calling
// In a condition before the task:
var resolved = await GetContentAsync(workflowContext);
if (resolved is null) throw new InvalidOperationException("UnpublishContentTask: no content item resolved from the configured expression."); Try / catch
try { await task.ExecuteAsync(workflowContext, activityContext); }
catch (InvalidOperationException ex) when (ex.Message.Contains("failed to retrieve the content item"))
{
logger.LogWarning(ex, "Unpublish skipped: no resolvable content item.");
} Prevention
- Set ContentItemId/ContentItem expressions explicitly in the activity.
- For non-content triggers, load or pass the item explicitly.
- Verify expression output with a Log task during development.
- Skip the task via a condition when the variable is empty.
When it happens
Trigger: The activity's ContentItemId expression (or ContentItem expression) evaluates to null — empty field, misspelled workflow variable, or the preceding event provided no content item input.
Common situations: Designer left the content item field blank; workflow was started by a non-content trigger (e.g. timer) with no content item in context.
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 'RetrieveContentTask' failed to evaluate the…
- 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/ca5611e87d2c615f.
Report an issue: GitHub.
Appendix: source
Thrown at src/OrchardCore.Modules/OrchardCore.Contents/Workflows/Activities/UnpublishContentTask.cs:32
IWorkflowScriptEvaluator scriptEvaluator,
IStringLocalizer<UnpublishContentTask> localizer)
: base(contentManager, scriptEvaluator, localizer)
{
}
public override string Name => nameof(UnpublishContentTask);
public override LocalizedString DisplayText => S["Unpublish Content Task"];
public override LocalizedString Category => S["Content"];
public override IEnumerable<Outcome> GetPossibleOutcomes(WorkflowExecutionContext workflowContext, ActivityContext activityContext)
=> Outcome(S["Unpublished"], S["Noop"]);
public override async Task<ActivityExecutionResult> ExecuteAsync(WorkflowExecutionContext workflowContext, ActivityContext activityContext)
{
var content = (await GetContentAsync(workflowContext))
?? throw new InvalidOperationException($"The '{nameof(UnpublishContentTask)}' failed to retrieve the content item.");
if (string.Equals(InlineEvent.ContentItemId, content.ContentItem.ContentItemId, StringComparison.OrdinalIgnoreCase))
{
return Outcome("Noop");
}
var contentItem = await ContentManager.GetAsync(content.ContentItem.ContentItemId, VersionOptions.Latest);
if (contentItem == null)
{
if (content is ContentItemIdExpressionResult)
{
throw new InvalidOperationException($"The '{nameof(UnpublishContentTask)}' failed to retrieve the content item.");
}
contentItem = content.ContentItem;
}
View on GitHub (pinned to 4306c0717f)