{"record":{"id":"2c7ba642cf1d06ab","repo":"OrchardCMS/OrchardCore","slug":"the-publishcontenttask-can-t-publish-the-content-item-as-it","errorCode":null,"errorMessage":"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.","messagePattern":"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\\.","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"src/OrchardCore.Modules/OrchardCore.Contents/Workflows/Activities/PublishContentTask.cs","lineNumber":53,"sourceCode":"        {\n            return Outcome(\"Noop\");\n        }\n\n        var contentItem = await ContentManager.GetAsync(content.ContentItem.ContentItemId, VersionOptions.DraftRequired);\n\n        if (contentItem == null)\n        {\n            if (content is ContentItemIdExpressionResult)\n            {\n                throw new InvalidOperationException($\"The '{nameof(PublishContentTask)}' failed to retrieve the content item.\");\n            }\n\n            contentItem = content.ContentItem;\n        }\n\n        if (InlineEvent.IsStart && InlineEvent.ContentType == contentItem.ContentType && InlineEvent.Name == nameof(ContentPublishedEvent))\n        {\n            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.\");\n        }\n\n        await ContentManager.PublishAsync(contentItem);\n\n        return Outcome(\"Published\");\n    }\n}\n","sourceCodeStart":35,"sourceCodeEnd":61,"githubUrl":"https://github.com/OrchardCMS/OrchardCore/blob/4306c0717fe573f6fca1b4955909ddab6a192807/src/OrchardCore.Modules/OrchardCore.Contents/Workflows/Activities/PublishContentTask.cs#L35-L61","documentation":"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.","triggerScenarios":"Workflow whose starting activity is ContentPublishedEvent (IsStart=true, ContentType = X) contains a PublishContentTask resolving an item whose ContentType is X, executed inline.","commonSituations":"'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.","solutions":["Point the PublishContentTask at a different content type than the ContentPublishedEvent trigger.","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.","Trigger on ContentDraftSavedEvent instead and publish from there for a different type.","Catch InvalidOperationException in host workflow execution code to log and skip the looping run."],"exampleFix":"// before\n// Trigger: ContentPublishedEvent { ContentType: \"NewsItem\" }, PublishContentTask resolves 'NewsItem'\n// after\n// Trigger: ContentDraftSavedEvent { ContentType: \"NewsItem\" }, PublishContentTask publishes it","handlingStrategy":"validation","validationCode":"// Before triggering a ContentPublishedEvent-started workflow\nif (triggerIsStart && triggerEvent == \"ContentPublishedEvent\" &&\n    string.Equals(resolvedTargetContentType, triggerContentType, StringComparison.OrdinalIgnoreCase))\n    throw new InvalidOperationException(\"PublishContentTask would republish inline and loop; reconfigure.\");","typeGuard":null,"tryCatchPattern":"try { await workflowManager.TriggerEventAsync(nameof(ContentPublishedEvent), contentItem); }\ncatch (InvalidOperationException ex) when (ex.Message.Contains(\"PublishContentTask\") && ex.Message.Contains(\"infinitive loop\"))\n{\n    logger.LogWarning(ex, \"Republish loop prevented; change trigger or task target.\");\n}","preventionTips":["Never pair a same-type ContentPublishedEvent trigger with a PublishContentTask on that type.","Trigger on ContentDraftSavedEvent when the goal is to publish after edits.","Verify bulk-update workflows target a different type than their trigger.","Review imported recipes for event/task content-type collisions before enabling."],"tags":["orchardcore","workflows","infinite-loop","contents"],"backgroundTag":"invalid-state-transition","analyzedSha":"4306c0717fe573f6fca1b4955909ddab6a192807","analyzedAt":"2026-09-13T17:41:05.024Z","contentChangedAt":"2026-09-13T17:41:05.024Z","schemaVersion":2},"datasetVersion":"2026-09-16T04:17:20.429Z"}