OrchardCMS/OrchardCore · error · InvalidOperationException

The 'CreateContentTask' can't create the content item as it…

Error message

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.

What it means

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.

Solutions

  1. Change the CreateContentTask's ContentType so it differs from the ContentDraftSavedEvent's content type.
  2. 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.
  3. Use a different starting event or disable inline execution with a manual recursion guard.
  4. Handle InvalidOperationException in host workflow-triggering code to log and suppress the loop attempt.

Example fix

// before
// Trigger: ContentDraftSavedEvent { ContentType: "Doc" }, CreateContentTask { ContentType: "Doc", Publish: false }
// after
CreateContentTask { ContentType: "DocRevision", Publish: false }
Defensive patterns

Strategy: validation

Validate before calling

// Validate before triggering
if (!taskPublish && triggerEvent == "ContentDraftSavedEvent" && triggerIsStart &&
    string.Equals(triggerContentType, taskContentType, StringComparison.OrdinalIgnoreCase))
    throw new InvalidOperationException("Draft-creating inline from ContentDraftSavedEvent of the same type would loop.");

Try / catch

try { await workflowManager.TriggerEventAsync(nameof(ContentDraftSavedEvent), ...); }
catch (InvalidOperationException ex) when (ex.Message.Contains("CreateContentTask") && ex.Message.Contains("ContentDraftSavedEvent"))
{
    logger.LogWarning(ex, "Draft-save loop prevented; change task ContentType.");
}

Prevention

When it happens

Trigger: CreateContentTask with Publish=false inside a workflow whose starting activity is ContentDraftSavedEvent (IsStart=true) for the same ContentType, invoked inline.

Common situations: 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.

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/e3e0396531339972. Report an issue: GitHub.

Appendix: source

Thrown at src/OrchardCore.Modules/OrchardCore.Contents/Workflows/Activities/CreateContentTask.cs:88

        {
            if (InlineEvent.Name == nameof(ContentUpdatedEvent))
            {
                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.");
            }

            if (InlineEvent.Name == nameof(ContentCreatedEvent))
            {
                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.");
            }

            if (Publish && InlineEvent.Name == nameof(ContentPublishedEvent))
            {
                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.");
            }

            if (!Publish && InlineEvent.Name == nameof(ContentDraftSavedEvent))
            {
                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.");
            }
        }

        var contentItem = await ContentManager.NewAsync(ContentType);

        if (!string.IsNullOrWhiteSpace(ContentProperties.Expression))
        {
            var contentProperties = await _expressionEvaluator.EvaluateAsync(ContentProperties, workflowContext, _javaScriptEncoder);
            contentItem.Merge(JObject.Parse(contentProperties));
        }

        var result = await ContentManager.ValidateAsync(contentItem);

        if (result.Succeeded)
        {
            await ContentManager.CreateAsync(contentItem, VersionOptions.Draft);

            if (Publish)

View on GitHub (pinned to 4306c0717f)