{"record":{"id":"c118fee4923c9232","repo":"OrchardCMS/OrchardCore","slug":"the-createcontenttask-can-t-create-the-content-item-as-it-is","errorCode":null,"errorMessage":"The 'CreateContentTask' can't create the content item as it is executed inline from a starting 'ContentCreatedEvent' 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 'ContentCreatedEvent' 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":78,"sourceCode":"    {\n        return !string.IsNullOrEmpty(ContentType);\n    }\n\n    public override IEnumerable<Outcome> GetPossibleOutcomes(WorkflowExecutionContext workflowContext, ActivityContext activityContext)\n        => 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);","sourceCodeStart":60,"sourceCodeEnd":96,"githubUrl":"https://github.com/OrchardCMS/OrchardCore/blob/4306c0717fe573f6fca1b4955909ddab6a192807/src/OrchardCore.Modules/OrchardCore.Contents/Workflows/Activities/CreateContentTask.cs#L60-L96","documentation":"CreateContentTask.ExecuteAsync throws this InvalidOperationException when the workflow runs inline from a starting ContentCreatedEvent whose content type equals the content type the task is configured to create. Creating that content would emit another ContentCreatedEvent inline, re-running the workflow forever. Orchard Core throws instead of allowing the recursion.","triggerScenarios":"Workflow with a starting ContentCreatedEvent activity (IsStart=true, ContentType = X) containing a CreateContentTask whose ContentType is also X; the workflow is triggered inline during content creation of X.","commonSituations":"Developer wants 'whenever an Order is created, create an Invoice' but mistakenly sets the task's content type to 'Order' itself; copied workflow definitions between environments; content-type renamed so task and trigger now collide.","solutions":["Set the CreateContentTask's ContentType to a different type than the starting event's content type.","If a same-type child item is genuinely needed, disable inline execution for the workflow (run via the non-inline path) and add a guard condition to prevent recursion.","Split into two content types / use a different triggering event such as ContentPublishedEvent with matching Publish flag.","Wrap workflow execution in host code that catches InvalidOperationException for this guard and logs it."],"exampleFix":"// before\n// Trigger: ContentCreatedEvent { ContentType: \"Invoice\" }, Task: CreateContentTask { ContentType: \"Invoice\" }\n// after\n// Task: CreateContentTask { ContentType: \"InvoiceReceipt\" } // distinct type breaks the loop","handlingStrategy":"validation","validationCode":"// Validate before triggering\nif (triggerEvent == \"ContentCreatedEvent\" && triggerIsStart &&\n    string.Equals(triggerContentType, taskContentType, StringComparison.OrdinalIgnoreCase))\n    throw new InvalidOperationException(\"CreateContentTask would recurse: same content type as the ContentCreatedEvent trigger.\");","typeGuard":null,"tryCatchPattern":"try { await workflowManager.TriggerEventAsync(nameof(ContentCreatedEvent), ...); }\ncatch (InvalidOperationException ex) when (ex.Message.Contains(\"CreateContentTask\") && ex.Message.Contains(\"ContentCreatedEvent\"))\n{\n    logger.LogWarning(ex, \"Content creation loop prevented; fix task ContentType.\");\n}","preventionTips":["Design workflows so the created content type differs from the triggering one (e.g. Order → Invoice).","If a same-type child is needed, use a non-inline execution path with an explicit recursion flag.","Review imported recipes for trigger/task content-type collisions.","Unit test workflow definitions that pair ContentCreatedEvent with CreateContentTask."],"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"}