OrchardCMS/OrchardCore · error · InvalidOperationException

The 'PublishContentTask' can't publish the content item as…

Error message

The 'PublishContentTask' can't publish the content item as it is executed inline from a starting 'ContentPublishedEvent' of the same content type, which would result in an infinitive loop.

What it means

PublishContentTask throws this InvalidOperationException when it executes inline from a starting ContentPublishedEvent for an item of the same content type. Publishing inline would emit another ContentPublishedEvent, re-triggering the workflow in an infinite loop, so Orchard Core refuses the operation.

Solutions

  1. Point the PublishContentTask at a different content type than the ContentPublishedEvent trigger.
  2. If re-publishing the same item is intended, remove the redundant task or run the workflow non-inline with an explicit condition that stops after one iteration.
  3. Trigger on ContentDraftSavedEvent instead and publish from there for a different type.
  4. Catch InvalidOperationException in host workflow execution code to log and skip the looping run.

Example fix

// before
// Trigger: ContentPublishedEvent { ContentType: "NewsItem" }, PublishContentTask resolves 'NewsItem'
// after
// Trigger: ContentDraftSavedEvent { ContentType: "NewsItem" }, PublishContentTask publishes it
Defensive patterns

Strategy: validation

Validate before calling

// Before triggering a ContentPublishedEvent-started workflow
if (triggerIsStart && triggerEvent == "ContentPublishedEvent" &&
    string.Equals(resolvedTargetContentType, triggerContentType, StringComparison.OrdinalIgnoreCase))
    throw new InvalidOperationException("PublishContentTask would republish inline and loop; reconfigure.");

Try / catch

try { await workflowManager.TriggerEventAsync(nameof(ContentPublishedEvent), contentItem); }
catch (InvalidOperationException ex) when (ex.Message.Contains("PublishContentTask") && ex.Message.Contains("infinitive loop"))
{
    logger.LogWarning(ex, "Republish loop prevented; change trigger or task target.");
}

Prevention

When it happens

Trigger: Workflow whose starting activity is ContentPublishedEvent (IsStart=true, ContentType = X) contains a PublishContentTask resolving an item whose ContentType is X, executed inline.

Common situations: 'When a Product is published, publish it again after modification' style self-publishing rules; bulk-update workflows targeting the same type as their trigger; recipes importing trigger/task pairs with matching content types.

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


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

Appendix: source

Thrown at src/OrchardCore.Modules/OrchardCore.Contents/Workflows/Activities/PublishContentTask.cs:53

        {
            return Outcome("Noop");
        }

        var contentItem = await ContentManager.GetAsync(content.ContentItem.ContentItemId, VersionOptions.DraftRequired);

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

            contentItem = content.ContentItem;
        }

        if (InlineEvent.IsStart && InlineEvent.ContentType == contentItem.ContentType && InlineEvent.Name == nameof(ContentPublishedEvent))
        {
            throw new InvalidOperationException($"The '{nameof(PublishContentTask)}' 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.");
        }

        await ContentManager.PublishAsync(contentItem);

        return Outcome("Published");
    }
}

View on GitHub (pinned to 4306c0717f)