OrchardCMS/OrchardCore · error · InvalidOperationException
The 'CreateContentTask' can't publish the content item as…
Error message
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.
What it means
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.
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.
Example fix
// before
// Trigger: ContentPublishedEvent { ContentType: "Post" }, CreateContentTask { ContentType: "Post", Publish: true }
// after
CreateContentTask { ContentType: "PostNotification", Publish: true } Defensive patterns
Strategy: validation
Validate before calling
// Validate before triggering
if (taskPublish && triggerEvent == "ContentPublishedEvent" && triggerIsStart &&
string.Equals(triggerContentType, taskContentType, StringComparison.OrdinalIgnoreCase))
throw new InvalidOperationException("Publishing inline from ContentPublishedEvent of the same type would loop."); Try / catch
try { await workflowManager.TriggerEventAsync(nameof(ContentPublishedEvent), ...); }
catch (InvalidOperationException ex) when (ex.Message.Contains("CreateContentTask") && ex.Message.Contains("ContentPublishedEvent"))
{
logger.LogWarning(ex, "Publish loop prevented; adjust task or trigger.");
} Prevention
- 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.
When it happens
Trigger: CreateContentTask with Publish=true inside a workflow whose starting activity is ContentPublishedEvent (IsStart=true) for the same ContentType, triggered inline.
Common situations: 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.
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
- The 'CreateContentTask' can't update the content item as it…
- The 'CreateContentTask' can't create the content item as it…
- The 'CreateContentTask' can't create the content item as it…
- The 'DeleteContentTask' can't delete the content item as it…
- The 'PublishContentTask' can't publish the content item as…
AI-assisted analysis of OrchardCMS/OrchardCore@4306c0717f (2026-09-13).
Data as JSON: /api/errors/72271c34fa874bf6.
Report an issue: GitHub.
Appendix: source
Thrown at src/OrchardCore.Modules/OrchardCore.Contents/Workflows/Activities/CreateContentTask.cs:83
=> Outcome(S["Done"], S["Failed"]);
public override async Task<ActivityExecutionResult> ExecuteAsync(WorkflowExecutionContext workflowContext, ActivityContext activityContext)
{
if (InlineEvent.IsStart && InlineEvent.ContentType == ContentType)
{
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);
View on GitHub (pinned to 4306c0717f)