OrchardCMS/OrchardCore · error · InvalidOperationException

The 'UpdateContentTask' failed to retrieve the content item.

Error message

The 'UpdateContentTask' failed to retrieve the content item.

What it means

UpdateContentTask could not resolve any content item to update: the evaluated ID path yielded nothing and the workflow input contained no IContent under ContentEventConstants.ContentItemInputKey. The activity throws rather than silently doing nothing.

Solutions

  1. Provide a valid ContentItemId expression on the activity so the item resolves by ID.
  2. Start the workflow from a content event that injects the content item input, or manually add the input under ContentEventConstants.ContentItemInputKey.
  3. Add a preceding task that loads the content item into workflow context.
  4. Log the workflow input before this task to confirm what is available.

Example fix

// before
workflowContext.Input lacks ContentItemInputKey; task has no ContentItemId
// after
ContentItemId: "{{ Workflow.Input.ContentItem.ContentItemId }}" or pass IContent input keyed ContentEventConstants.ContentItemInputKey
Defensive patterns

Strategy: validation

Validate before calling

var input = workflowContext.Input.GetValue<IContent>(ContentEventConstants.ContentItemInputKey);
if (input?.ContentItem is null && string.IsNullOrWhiteSpace(configuredContentItemId))
    throw new InvalidOperationException("UpdateContentTask: no content item input and no ContentItemId 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, "UpdateContentTask aborted: no content item could be resolved.");
}

Prevention

When it happens

Trigger: contentItem remains null after all resolution attempts — no valid ContentItemId expression result and no content item present in the workflow input (e.g. workflow started by a non-content trigger).

Common situations: Timer/HTTP-triggered workflows with no content item context; a custom trigger that doesn't set the standard ContentItemInputKey input.

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/3b5b27cd3aa7d181. Report an issue: GitHub.

Appendix: source

Thrown at src/OrchardCore.Modules/OrchardCore.Contents/Workflows/Activities/UpdateContentTask.cs:105

            {
                throw new InvalidOperationException($"The '{nameof(UpdateContentTask)}' can't update the content item as it is executed inline from a '{nameof(ContentDraftSavedEvent)}' of the same content item, please use an event that is triggered earlier.");
            }
        }

        ContentItem contentItem = null;

        if (!inlineEventOfSameContentItemId)
        {
            contentItem = await ContentManager.GetAsync(contentItemId, VersionOptions.DraftRequired);
        }
        else
        {
            contentItem = workflowContext.Input.GetValue<IContent>(ContentEventConstants.ContentItemInputKey)?.ContentItem;
        }

        if (contentItem == null)
        {
            throw new InvalidOperationException($"The '{nameof(UpdateContentTask)}' failed to retrieve the content item.");
        }

        if (!inlineEventOfSameContentItemId && InlineEvent.IsStart && InlineEvent.ContentType == contentItem.ContentType)
        {
            if (InlineEvent.Name == nameof(ContentUpdatedEvent))
            {
                throw new InvalidOperationException($"The '{nameof(UpdateContentTask)}' can't update the content item as it is executed inline from a starting '{nameof(ContentUpdatedEvent)}' of the same content type, which would result in an infinitive loop.");
            }

            if (Publish && InlineEvent.Name == nameof(ContentPublishedEvent))
            {
                throw new InvalidOperationException($"The '{nameof(UpdateContentTask)}' can't publish the content item as it is executed inline from a starting '{nameof(ContentPublishedEvent)}' of the same content type, which would result in an infinitive loop.");
            }

            if (!Publish && InlineEvent.Name == nameof(ContentDraftSavedEvent))
            {
                throw new InvalidOperationException($"The '{nameof(UpdateContentTask)}' can't update the content item as it is executed inline from a starting '{nameof(ContentDraftSavedEvent)}' of the same content type, which would result in an infinitive loop.");
            }

View on GitHub (pinned to 4306c0717f)