OrchardCMS/OrchardCore · error · ValidationException

string.Join(", ", result.Errors)

Error message

string.Join(", ", result.Errors)

What it means

The CreateContentItem scripting method validates the new content item via IContentManager.ValidateAsync before saving. If validation fails, it cancels the YesSql session (so nothing is persisted) and throws a ValidationException whose message is the joined validation errors from all handlers.

Solutions

  1. Read the joined error message — it lists each validation failure from result.Errors — and correct the corresponding property in the 'properties' object.
  2. Provide required parts/fields (e.g. TitlePart title) in the properties argument before creating.
  3. Pre-validate the values in your script/workflow before invoking createContentItem.
  4. If validation rules are too strict for automation, adjust the relevant handler/settings rather than bypassing validation.

Example fix

// before (scripting)
createContentItem('Article', null, %{ TitlePart: %{ Title: '' } })
// after
createContentItem('Article', null, %{ TitlePart: %{ Title: 'Hello World' } })
Defensive patterns

Strategy: try-catch

Validate before calling

// scripting pre-check: ensure required properties present before createContentItem
if (!properties.ContainsKey("TitlePart")) throw new Error("TitlePart is required");

Try / catch

try
{
    var item = createContentItem('Article', null, properties);
}
catch (e) {
    // e.message lists joined validation failures
    logger.error('Content validation failed: ' + e.message);
}

Prevention

When it happens

Trigger: Calling the 'createContentItem' scripting function with property values that fail content validation handlers — e.g. missing required part data, invalid Autoroute/Title values, or any IContentHandler validation failure.

Common situations: Workflow or script-generated content missing required fields; importing data via scripts that violates validation rules; template/liquid or rules scripts building items with empty required parts.

Understand the failure class

Background: Schema validation failed / invalid input schema: payload rejected because its shape doesn't match the expected schema — this error's family across 28 libraries.

Related errors


AI-assisted analysis of OrchardCMS/OrchardCore@4306c0717f (2026-09-13). Data as JSON: /api/errors/1a5d60b0fc875194. Report an issue: GitHub.

Appendix: source

Thrown at src/OrchardCore.Modules/OrchardCore.Contents/Scripting/ContentMethodsProvider.cs:85

    private static async Task<IContent> CreateContentItemAsync(IServiceProvider serviceProvider, string contentType, bool? publish, object properties)
    {
        var contentManager = serviceProvider.GetRequiredService<IContentManager>();
        var contentItem = await contentManager.NewAsync(contentType);
        contentItem.Merge(properties);

        var result = await contentManager.ValidateAsync(contentItem);

        if (result.Succeeded)
        {
            await contentManager.CreateAsync(contentItem, publish == true ? VersionOptions.Published : VersionOptions.Draft);

            return contentItem;
        }

        var session = serviceProvider.GetRequiredService<YesSql.ISession>();
        await session.CancelAsync();
        throw new ValidationException(string.Join(", ", result.Errors));
    }

    private static async Task UpdateContentItemAsync(IServiceProvider serviceProvider, ContentItem contentItem, object properties)
    {
        var contentManager = serviceProvider.GetRequiredService<IContentManager>();
        contentItem.Merge(properties, new JsonMergeSettings { MergeArrayHandling = MergeArrayHandling.Replace });
        await contentManager.UpdateAsync(contentItem);
        var result = await contentManager.ValidateAsync(contentItem);
        if (!result.Succeeded)
        {
            var session = serviceProvider.GetRequiredService<YesSql.ISession>();
            await session.CancelAsync();
            throw new ValidationException(string.Join(", ", result.Errors));
        }
    }

    private static async Task DeleteContentItemAsync(IServiceProvider serviceProvider, ContentItem contentItem)
    {

View on GitHub (pinned to 4306c0717f)