{"record":{"id":"1a5d60b0fc875194","repo":"OrchardCMS/OrchardCore","slug":"string-join-result-errors","errorCode":null,"errorMessage":"string.Join(\", \", result.Errors)","messagePattern":"string\\.Join\\(\", \", result\\.Errors\\)","errorType":"validation","errorClass":"ValidationException","httpStatus":null,"severity":"error","filePath":"src/OrchardCore.Modules/OrchardCore.Contents/Scripting/ContentMethodsProvider.cs","lineNumber":85,"sourceCode":"\n    private static async Task<IContent> CreateContentItemAsync(IServiceProvider serviceProvider, string contentType, bool? publish, object properties)\n    {\n        var contentManager = serviceProvider.GetRequiredService<IContentManager>();\n        var contentItem = await contentManager.NewAsync(contentType);\n        contentItem.Merge(properties);\n\n        var result = await contentManager.ValidateAsync(contentItem);\n\n        if (result.Succeeded)\n        {\n            await contentManager.CreateAsync(contentItem, publish == true ? VersionOptions.Published : VersionOptions.Draft);\n\n            return contentItem;\n        }\n\n        var session = serviceProvider.GetRequiredService<YesSql.ISession>();\n        await session.CancelAsync();\n        throw new ValidationException(string.Join(\", \", result.Errors));\n    }\n\n    private static async Task UpdateContentItemAsync(IServiceProvider serviceProvider, ContentItem contentItem, object properties)\n    {\n        var contentManager = serviceProvider.GetRequiredService<IContentManager>();\n        contentItem.Merge(properties, new JsonMergeSettings { MergeArrayHandling = MergeArrayHandling.Replace });\n        await contentManager.UpdateAsync(contentItem);\n        var result = await contentManager.ValidateAsync(contentItem);\n        if (!result.Succeeded)\n        {\n            var session = serviceProvider.GetRequiredService<YesSql.ISession>();\n            await session.CancelAsync();\n            throw new ValidationException(string.Join(\", \", result.Errors));\n        }\n    }\n\n    private static async Task DeleteContentItemAsync(IServiceProvider serviceProvider, ContentItem contentItem)\n    {","sourceCodeStart":67,"sourceCodeEnd":103,"githubUrl":"https://github.com/OrchardCMS/OrchardCore/blob/4306c0717fe573f6fca1b4955909ddab6a192807/src/OrchardCore.Modules/OrchardCore.Contents/Scripting/ContentMethodsProvider.cs#L67-L103","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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."],"exampleFix":"// before (scripting)\ncreateContentItem('Article', null, %{ TitlePart: %{ Title: '' } })\n// after\ncreateContentItem('Article', null, %{ TitlePart: %{ Title: 'Hello World' } })","handlingStrategy":"try-catch","validationCode":"// scripting pre-check: ensure required properties present before createContentItem\nif (!properties.ContainsKey(\"TitlePart\")) throw new Error(\"TitlePart is required\");","typeGuard":null,"tryCatchPattern":"try\n{\n    var item = createContentItem('Article', null, properties);\n}\ncatch (e) {\n    // e.message lists joined validation failures\n    logger.error('Content validation failed: ' + e.message);\n}","preventionTips":["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."],"tags":["scripting","validation","content-items"],"backgroundTag":"schema-validation-failed","analyzedSha":"4306c0717fe573f6fca1b4955909ddab6a192807","analyzedAt":"2026-09-13T17:41:05.024Z","contentChangedAt":"2026-09-13T17:41:05.024Z","schemaVersion":2},"datasetVersion":"2026-09-16T04:17:20.429Z"}