{"record":{"id":"e3e0396531339972","repo":"OrchardCMS/OrchardCore","slug":"the-createcontenttask-can-t-create-the-content-item-as-it-is-e3e039","errorCode":null,"errorMessage":"The 'CreateContentTask' can't create the content item as it is executed inline from a starting 'ContentDraftSavedEvent' of the same content type, which would result in an infinitive loop.","messagePattern":"The 'CreateContentTask' can't create the content item as it is executed inline from a starting 'ContentDraftSavedEvent' 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":88,"sourceCode":"        {\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\n        if (result.Succeeded)\n        {\n            await ContentManager.CreateAsync(contentItem, VersionOptions.Draft);\n\n            if (Publish)","sourceCodeStart":70,"sourceCodeEnd":106,"githubUrl":"https://github.com/OrchardCMS/OrchardCore/blob/4306c0717fe573f6fca1b4955909ddab6a192807/src/OrchardCore.Modules/OrchardCore.Contents/Workflows/Activities/CreateContentTask.cs#L70-L106","documentation":"CreateContentTask.ExecuteAsync throws this InvalidOperationException when Publish is false and the workflow executes inline from a starting ContentDraftSavedEvent of the same content type. Creating (as draft) that content type would emit another ContentDraftSavedEvent inline, restarting the workflow endlessly. Orchard Core throws to prevent the infinite loop.","triggerScenarios":"CreateContentTask with Publish=false inside a workflow whose starting activity is ContentDraftSavedEvent (IsStart=true) for the same ContentType, invoked inline.","commonSituations":"Draft-save hooks that create a draft 'mirror' item of the same type; users configure draft workflows and leave the task's content type equal to the trigger's; workflows copied from publish-based examples where only the event was changed.","solutions":["Change the CreateContentTask's ContentType so it differs from the ContentDraftSavedEvent's content type.","Publish the created item instead (Publish=true) if a published sibling is acceptable — though the published variant has its own guard, so a different type is the real fix.","Use a different starting event or disable inline execution with a manual recursion guard.","Handle InvalidOperationException in host workflow-triggering code to log and suppress the loop attempt."],"exampleFix":"// before\n// Trigger: ContentDraftSavedEvent { ContentType: \"Doc\" }, CreateContentTask { ContentType: \"Doc\", Publish: false }\n// after\nCreateContentTask { ContentType: \"DocRevision\", Publish: false }","handlingStrategy":"validation","validationCode":"// Validate before triggering\nif (!taskPublish && triggerEvent == \"ContentDraftSavedEvent\" && triggerIsStart &&\n    string.Equals(triggerContentType, taskContentType, StringComparison.OrdinalIgnoreCase))\n    throw new InvalidOperationException(\"Draft-creating inline from ContentDraftSavedEvent of the same type would loop.\");","typeGuard":null,"tryCatchPattern":"try { await workflowManager.TriggerEventAsync(nameof(ContentDraftSavedEvent), ...); }\ncatch (InvalidOperationException ex) when (ex.Message.Contains(\"CreateContentTask\") && ex.Message.Contains(\"ContentDraftSavedEvent\"))\n{\n    logger.LogWarning(ex, \"Draft-save loop prevented; change task ContentType.\");\n}","preventionTips":["Never pair ContentDraftSavedEvent with a draft-creating task of the same content type.","Use a revision/audit content type for items created on draft save.","Check workflows copied from published-event examples for unchanged content types.","Smoke-test draft workflows after content-type renames."],"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"}