{"record":{"id":"72271c34fa874bf6","repo":"OrchardCMS/OrchardCore","slug":"the-createcontenttask-can-t-publish-the-content-item-as-it","errorCode":null,"errorMessage":"The 'CreateContentTask' 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 'CreateContentTask' 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/CreateContentTask.cs","lineNumber":83,"sourceCode":"        => Outcome(S[\"Done\"], S[\"Failed\"]);\n\n    public override async Task<ActivityExecutionResult> ExecuteAsync(WorkflowExecutionContext workflowContext, ActivityContext activityContext)\n    {\n        if (InlineEvent.IsStart && InlineEvent.ContentType == ContentType)\n        {\n            if (InlineEvent.Name == nameof(ContentUpdatedEvent))\n            {\n                throw new InvalidOperationException($\"The '{nameof(CreateContentTask)}' 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.\");\n            }\n\n            if (InlineEvent.Name == nameof(ContentCreatedEvent))\n            {\n                throw new InvalidOperationException($\"The '{nameof(CreateContentTask)}' can't create the content item as it is executed inline from a starting '{nameof(ContentCreatedEvent)}' of the same content type, which would result in an infinitive loop.\");\n            }\n\n            if (Publish && InlineEvent.Name == nameof(ContentPublishedEvent))\n            {\n                throw new InvalidOperationException($\"The '{nameof(CreateContentTask)}' 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            if (!Publish && InlineEvent.Name == nameof(ContentDraftSavedEvent))\n            {\n                throw new InvalidOperationException($\"The '{nameof(CreateContentTask)}' can't create 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.\");\n            }\n        }\n\n        var contentItem = await ContentManager.NewAsync(ContentType);\n\n        if (!string.IsNullOrWhiteSpace(ContentProperties.Expression))\n        {\n            var contentProperties = await _expressionEvaluator.EvaluateAsync(ContentProperties, workflowContext, _javaScriptEncoder);\n            contentItem.Merge(JObject.Parse(contentProperties));\n        }\n\n        var result = await ContentManager.ValidateAsync(contentItem);\n","sourceCodeStart":65,"sourceCodeEnd":101,"githubUrl":"https://github.com/OrchardCMS/OrchardCore/blob/4306c0717fe573f6fca1b4955909ddab6a192807/src/OrchardCore.Modules/OrchardCore.Contents/Workflows/Activities/CreateContentTask.cs#L65-L101","documentation":"CreateContentTask.ExecuteAsync throws this InvalidOperationException when Publish is true and the workflow executes inline from a starting ContentPublishedEvent of the same content type. Publishing the new content item would fire ContentPublishedEvent inline again, re-entering the workflow in an endless cycle. Orchard Core blocks the operation explicitly.","triggerScenarios":"CreateContentTask with Publish=true inside a workflow whose starting activity is ContentPublishedEvent (IsStart=true) for the same ContentType, triggered inline.","commonSituations":"Auto-publish a notification/related item whenever the same type is published; workflow imported from a recipe where the trigger and task target the same type; user selects 'publish' checkbox on the task while the trigger is ContentPublishedEvent.","solutions":["Uncheck Publish on the CreateContentTask or change its ContentType to differ from the trigger's content type.","Switch the starting event to ContentDraftSavedEvent with Publish=false, or another non-conflicting event.","Configure the workflow to not run inline and add an explicit anti-recursion condition (e.g. check a workflow output/property).","Catch InvalidOperationException around workflow triggering in host code and log the skipped run."],"exampleFix":"// before\n// Trigger: ContentPublishedEvent { ContentType: \"Post\" }, CreateContentTask { ContentType: \"Post\", Publish: true }\n// after\nCreateContentTask { ContentType: \"PostNotification\", Publish: true }","handlingStrategy":"validation","validationCode":"// Validate before triggering\nif (taskPublish && triggerEvent == \"ContentPublishedEvent\" && triggerIsStart &&\n    string.Equals(triggerContentType, taskContentType, StringComparison.OrdinalIgnoreCase))\n    throw new InvalidOperationException(\"Publishing inline from ContentPublishedEvent of the same type would loop.\");","typeGuard":null,"tryCatchPattern":"try { await workflowManager.TriggerEventAsync(nameof(ContentPublishedEvent), ...); }\ncatch (InvalidOperationException ex) when (ex.Message.Contains(\"CreateContentTask\") && ex.Message.Contains(\"ContentPublishedEvent\"))\n{\n    logger.LogWarning(ex, \"Publish loop prevented; adjust task or trigger.\");\n}","preventionTips":["Keep Publish=true tasks on content types other than the ContentPublishedEvent trigger type.","When the trigger is ContentPublishedEvent and the same type is targeted, drop the redundant publish.","Use ContentDraftSavedEvent + Publish if a publish-on-draft flow is intended (with a different type).","Document content-type pairing rules for workflow authors in your team."],"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-15T23:17:13.987Z"}