{"record":{"id":"0984ed01f2c48d26","repo":"OrchardCMS/OrchardCore","slug":"the-cloned-content-item-doesn-t-contain-a-localizationpart","errorCode":null,"errorMessage":"The cloned content item doesn't contain a LocalizationPart.","messagePattern":"The cloned content item doesn't contain a LocalizationPart\\.","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"src/OrchardCore.Modules/OrchardCore.ContentLocalization/Handlers/LocalizationPartHandler.cs","lineNumber":95,"sourceCode":"        return Task.CompletedTask;\n    }\n\n    public override Task RemovedAsync(RemoveContentContext context, LocalizationPart part)\n    {\n        if (!string.IsNullOrWhiteSpace(part.LocalizationSet) && part.Culture != null && context.NoActiveVersionLeft)\n        {\n            // Update entries from the index table after the session is committed.\n            return _entries.UpdateEntriesAsync();\n        }\n\n        return Task.CompletedTask;\n    }\n\n    public override Task CloningAsync(CloneContentContext context, LocalizationPart part)\n    {\n        if (!context.CloneContentItem.TryGet<LocalizationPart>(out var clonedPart))\n        {\n            throw new InvalidOperationException(\"The cloned content item doesn't contain a LocalizationPart.\");\n        }\n\n        clonedPart.LocalizationSet = string.Empty;\n        clonedPart.Apply();\n        return Task.CompletedTask;\n    }\n}\n","sourceCodeStart":77,"sourceCodeEnd":103,"githubUrl":"https://github.com/OrchardCMS/OrchardCore/blob/4306c0717fe573f6fca1b4955909ddab6a192807/src/OrchardCore.Modules/OrchardCore.ContentLocalization/Handlers/LocalizationPartHandler.cs#L77-L103","documentation":"LocalizationPartHandler.CloningAsync resets the clone's LocalizationSet so the clone does not share the original's localization group, but it requires the cloned content item to actually contain a LocalizationPart. If the clone lacks that part it throws InvalidOperationException, meaning the clone is inconsistent with the source part being handled.","triggerScenarios":"Cloning content where the source has LocalizationPart attached via its type, but the CloneContentItem was constructed manually or its type definition no longer includes LocalizationPart, so TryGet<LocalizationPart> fails.","commonSituations":"Custom clone code not copying all parts; LocalizationPart removed from the content type while old items still have it; recipe/import flows creating clones without the localization part.","solutions":["Ensure LocalizationPart is attached to the content type before cloning.","Use standard IContentManager clone flows that copy all parts.","Weld a LocalizationPart onto the clone item before invoking the clone pipeline.","Migrate legacy items so the part is present in both definition and item data."],"exampleFix":"// before\nvar clone = new ContentItem { ContentType = item.ContentType };\nawait _contentManager.CloneAsync(item);\n// after\nvar clone = item.Clone();\nclone.Weld(new LocalizationPart());\nawait _contentManager.CreateAsync(clone);","handlingStrategy":"validation","validationCode":"if (!context.CloneContentItem.TryGet<LocalizationPart>(out _)) throw new InvalidOperationException(\"Clone must carry LocalizationPart before cloning.\");","typeGuard":"static bool HasLocalization(ContentItem item) => item.TryGet<LocalizationPart>(out _);","tryCatchPattern":"try { await _contentManager.CloneAsync(item); }\ncatch (InvalidOperationException ex) when (ex.Message.Contains(\"LocalizationPart\"))\n{\n    logger.LogError(ex, \"Clone of {Id} lacks LocalizationPart\", item.ContentItemId);\n    throw;\n}","preventionTips":["Attach LocalizationPart to every translatable content type","Clone via standard content manager APIs","Migrate items when the part definition changes","Verify cloned items retain all source parts in tests"],"tags":["contentlocalization","localizationpart","cloning"],"backgroundTag":"missing-dependency","analyzedSha":"4306c0717fe573f6fca1b4955909ddab6a192807","analyzedAt":"2026-09-13T17:41:05.024Z","contentChangedAt":"2026-09-13T17:41:05.024Z","schemaVersion":2},"datasetVersion":"2026-09-15T23:17:13.987Z"}