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
- Read the joined error message — it lists each validation failure from result.Errors — and correct the corresponding property in the 'properties' object.
- Provide required parts/fields (e.g. TitlePart title) in the properties argument before creating.
- Pre-validate the values in your script/workflow before invoking createContentItem.
- 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
- Populate all required parts (e.g. TitlePart) in the properties object.
- Parse the joined error message to identify each failing validator.
- Test scripts against a tenant with the same validation handlers enabled.
- Cancel/rollback expectations: the method already cancels the session, so no partial save occurs.
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
- The 'Default' tenant can't be removed.
- ,
- Content part name must start with a letter
- Content part name contains invalid characters
- Content field name must start with a letter
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)