{"record":{"id":"8ba4b77cd115fb74","repo":"OrchardCMS/OrchardCore","slug":"the-cloned-content-item-doesn-t-contain-an-aliaspart","errorCode":null,"errorMessage":"The cloned content item doesn't contain an AliasPart.","messagePattern":"The cloned content item doesn't contain an AliasPart\\.","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"src/OrchardCore.Modules/OrchardCore.Alias/Handlers/AliasPartHandler.cs","lineNumber":83,"sourceCode":"    {\n        if (context.NoActiveVersionLeft)\n        {\n            return _tagCache.RemoveTagAsync(AliasConstants.AliasPrefix + instance.Alias);\n        }\n\n        return Task.CompletedTask;\n    }\n\n    public override Task UnpublishedAsync(PublishContentContext context, AliasPart instance)\n    {\n        return _tagCache.RemoveTagAsync(AliasConstants.AliasPrefix + instance.Alias);\n    }\n\n    public override async Task CloningAsync(CloneContentContext context, AliasPart part)\n    {\n        if (!context.CloneContentItem.TryGet<AliasPart>(out var clonedPart))\n        {\n            throw new InvalidOperationException(\"The cloned content item doesn't contain an AliasPart.\");\n        }\n\n        clonedPart.Alias = await GenerateUniqueAliasAsync(part.Alias, clonedPart);\n        clonedPart.Apply();\n    }\n\n    private async Task ComputeAliasAsync(AliasPart part)\n    {\n        // Compute the Alias only if it's empty.\n        if (!string.IsNullOrEmpty(part.Alias))\n        {\n            return;\n        }\n\n        var pattern = await GetPatternAsync(part);\n\n        if (!string.IsNullOrEmpty(pattern))\n        {","sourceCodeStart":65,"sourceCodeEnd":101,"githubUrl":"https://github.com/OrchardCMS/OrchardCore/blob/4306c0717fe573f6fca1b4955909ddab6a192807/src/OrchardCore.Modules/OrchardCore.Alias/Handlers/AliasPartHandler.cs#L65-L101","documentation":"Thrown by AliasPartHandler.CloningAsync when the cloned content item does not expose an AliasPart, even though the source part being handled exists. The handler must set a unique alias on the clone's own AliasPart; without it the clone would duplicate the alias, so the operation fails fast.","triggerScenarios":"Cloning a content item whose AliasPart was removed/altered between loading the source and building the clone; custom clone pipelines that copy only some parts; content-type changes dropping AliasPart while old items still carry it.","commonSituations":"Custom clone handlers or workflows modifying CloneContentItem before the driver runs; migrations changing content type definitions; recipes importing items with mismatched part data.","solutions":["Ensure the cloned content item retains its AliasPart during cloning (do not strip parts in custom clone handlers).","Check content type definitions so AliasPart remains attached to types whose items rely on aliases.","Inspect CloneContentItem.Content and re-attach the AliasPart before/around the clone operation.","Catch InvalidOperationException to fall back to a manual unique-alias assignment."],"exampleFix":"// before\nawait _contentManager.CloneAsync(contentItem); // custom handler removed AliasPart from clone\n// after\nvar clone = await _contentManager.CloneAsync(contentItem);\nif (!clone.TryGet<AliasPart>(out var aliasPart)) { aliasPart = new AliasPart(); clone.Weld(aliasPart); }\naliasPart.Alias = await _aliasPartHandlerAliasGenerator.GenerateUniqueAliasAsync(...);","handlingStrategy":"try-catch","validationCode":"if (!context.CloneContentItem.TryGet<AliasPart>(out _)) { /* re-weld AliasPart before cloning */ }","typeGuard":"bool CloneHasAliasPart(CloneContentContext ctx) => ctx.CloneContentItem?.TryGet<AliasPart>(out _) == true;","tryCatchPattern":"try { await _contentManager.CloneAsync(item); }\ncatch (InvalidOperationException ex) when (ex.Message.Contains(\"AliasPart\"))\n{ _logger.LogError(ex, \"Clone lost AliasPart for {Id}\", item.ContentItemId); }","preventionTips":["Never strip parts in custom clone handlers before drivers run","Keep AliasPart attached in content type definitions","Test cloning after content-definition migrations","Re-weld missing parts on clones before applying handlers"],"tags":["alias","cloning","content-parts"],"backgroundTag":"missing-dependency","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"}