OrchardCMS/OrchardCore · error · InvalidOperationException
The 'UpdateContentTask' can't update the content item as it…
Error message
The 'UpdateContentTask' can't update the content item as it is executed inline from a 'ContentPublishedEvent' of the same content item, please use an event that is triggered earlier.
What it means
Inline re-entrancy guard: if UpdateContentTask runs inline within a ContentPublishedEvent of the same content item it targets, updating would republish the item and re-trigger the event indefinitely. The library throws to prevent this loop and advises using an earlier-triggering event.
Solutions
- Start the workflow from ContentDraftSavedEvent or another earlier event instead of ContentPublishedEvent.
- Update a different content item than the one that triggered the event.
- Use a 'Content Updated'-style event with a content type filter that excludes re-entrancy, or run the update via a non-inline path.
- Set a loop-protection condition comparing item IDs before the task.
Example fix
// before Workflow start: ContentPublishedEvent -> UpdateContentTask (same item) // after Workflow start: ContentDraftSavedEvent -> UpdateContentTask (same item)
Defensive patterns
Strategy: validation
Validate before calling
if (inlineEvent?.Name == nameof(ContentPublishedEvent) && string.Equals(inlineEvent.ContentItemId, targetId, StringComparison.OrdinalIgnoreCase))
throw new InvalidOperationException("UpdateContentTask would re-enter ContentPublishedEvent for the same item."); Try / catch
try { await task.ExecuteAsync(workflowContext, activityContext); }
catch (InvalidOperationException ex) when (ex.Message.Contains("ContentPublishedEvent"))
{
logger.LogWarning(ex, "Inline update-after-publish loop prevented.");
} Prevention
- Do not put UpdateContentTask (same item) directly after ContentPublishedEvent.
- Use ContentDraftSavedEvent or another earlier trigger for same-item updates.
- Compare event and target item IDs in a condition before updating.
- Publish-changing updates belong before the publish completes (handler), not after.
When it happens
Trigger: InlineEvent.Name == 'ContentPublishedEvent' and the event's ContentItemId equals the activity's evaluated contentItemId (inline execution during publish of that same item).
Common situations: Workflow: ContentPublishedEvent -> UpdateContentTask on the same item (e.g. setting a field on publish). The publish inside Update re-fires the event.
Understand the failure class
Background: "Invalid state transition" errors: "status must be X, actually Y", "already rejected/charging/uninstalled", "cannot ... while running" — what they mean when a library rejects your call — this error's family across 31 libraries.
Related errors
- The 'UnpublishContentTask' can't unpublish the content item…
- The 'UpdateContentTask' can't update the content item as it…
- The 'UpdateContentTask' can't update the content item as it…
- The 'UpdateContentTask' can't publish the content item as…
- The 'UpdateContentTask' can't update the content item as it…
AI-assisted analysis of OrchardCMS/OrchardCore@4306c0717f (2026-09-13).
Data as JSON: /api/errors/921e9deb2a3aa323.
Report an issue: GitHub.
Appendix: source
Thrown at src/OrchardCore.Modules/OrchardCore.Contents/Workflows/Activities/UpdateContentTask.cs:83
set => SetProperty(value);
}
public override IEnumerable<Outcome> GetPossibleOutcomes(WorkflowExecutionContext workflowContext, ActivityContext activityContext)
=> Outcome(S["Done"], S["Failed"]);
public override async Task<ActivityExecutionResult> ExecuteAsync(WorkflowExecutionContext workflowContext, ActivityContext activityContext)
{
var contentItemId = (await GetContentItemIdAsync(workflowContext))
?? throw new InvalidOperationException($"The {nameof(UpdateContentTask)} failed to evaluate the 'ContentItemId'.");
var inlineEventOfSameContentItemId = string.Equals(InlineEvent.ContentItemId, contentItemId, StringComparison.OrdinalIgnoreCase);
if (inlineEventOfSameContentItemId)
{
if (InlineEvent.Name == nameof(ContentPublishedEvent))
{
throw new InvalidOperationException($"The '{nameof(UpdateContentTask)}' can't update the content item as it is executed inline from a '{nameof(ContentPublishedEvent)}' of the same content item, please use an event that is triggered earlier.");
}
if (InlineEvent.Name == nameof(ContentDraftSavedEvent))
{
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;
}View on GitHub (pinned to 4306c0717f)