OrchardCMS/OrchardCore · error · InvalidOperationException

The 'DeleteContentTask' failed to retrieve the content item.

Error message

The 'DeleteContentTask' failed to retrieve the content item.

What it means

DeleteContentTask.ExecuteAsync calls GetContentAsync to resolve the content item from the workflow context or a configured expression; if it returns null the task throws this InvalidOperationException. It means no content item could be resolved for deletion — the expression evaluated to nothing or referenced a missing item.

Solutions

  1. Fix the ContentItem/ContentItemId expression so it resolves a real content item (verify the property name and that the item exists).
  2. Ensure upstream workflow activities actually set the ContentItem/ContentItemId on the workflow context before DeleteContentTask runs.
  3. Guard the workflow with a condition activity that checks the resolved value is non-null before the delete step.
  4. Catch InvalidOperationException in host code around workflow execution and log which activity failed.

Example fix

// before: expression points at a non-existent property
ContentItem = '{{ Workflow.Input."ContenItem" }}'
// after
ContentItem = '{{ Workflow.Input."ContentItem" }}'
Defensive patterns

Strategy: validation

Validate before calling

// Before the workflow runs, resolve the expression yourself
var item = await expressionEvaluator.EvaluateAsync(taskExpression, workflowContext) as ContentItem;
if (item is null)
    throw new InvalidOperationException("DeleteContentTask expression resolves to no content item.");

Type guard

// C# narrowing
static bool HasContentItem(object value) => value is ContentItem { ContentItemId: > 0 };

Try / catch

try { await workflowManager.TriggerEventAsync(eventName, contentItem); }
catch (InvalidOperationException ex) when (ex.Message.Contains("DeleteContentTask") && ex.Message.Contains("failed to retrieve"))
{
    logger.LogWarning(ex, "Delete skipped: no content item resolved.");
}

Prevention

When it happens

Trigger: DeleteContentTask with a ContentItem expression that evaluates to null, or a ContentItemIdExpressionResult whose ID does not match any existing item, during ExecuteAsync.

Common situations: Typo or wrong property path in the expression; the item was already deleted by a prior workflow step; Liquid/Javascript expression returns an object of the wrong shape so the resolved content is null.

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


AI-assisted analysis of OrchardCMS/OrchardCore@4306c0717f (2026-09-13). Data as JSON: /api/errors/7796e2f44cb7e753. Report an issue: GitHub.

Appendix: source

Thrown at src/OrchardCore.Modules/OrchardCore.Contents/Workflows/Activities/DeleteContentTask.cs:31

        IWorkflowScriptEvaluator scriptEvaluator,
        IStringLocalizer<DeleteContentTask> localizer)
        : base(contentManager, scriptEvaluator, localizer)
    {
    }

    public override string Name => nameof(DeleteContentTask);

    public override LocalizedString DisplayText => S["Delete Content Task"];

    public override LocalizedString Category => S["Content"];

    public override IEnumerable<Outcome> GetPossibleOutcomes(WorkflowExecutionContext workflowContext, ActivityContext activityContext)
        => Outcome(S["Deleted"], S["Noop"]);

    public override async Task<ActivityExecutionResult> ExecuteAsync(WorkflowExecutionContext workflowContext, ActivityContext activityContext)
    {
        var content = (await GetContentAsync(workflowContext))
            ?? throw new InvalidOperationException($"The '{nameof(DeleteContentTask)}' 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(DeleteContentTask)}' failed to retrieve the content item.");
            }

            contentItem = content.ContentItem;
        }

View on GitHub (pinned to 4306c0717f)