OrchardCMS/OrchardCore · error · InvalidOperationException

The cloned content item doesn't contain an AliasPart.

Error message

The cloned content item doesn't contain an AliasPart.

What it means

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.

Solutions

  1. Ensure the cloned content item retains its AliasPart during cloning (do not strip parts in custom clone handlers).
  2. Check content type definitions so AliasPart remains attached to types whose items rely on aliases.
  3. Inspect CloneContentItem.Content and re-attach the AliasPart before/around the clone operation.
  4. Catch InvalidOperationException to fall back to a manual unique-alias assignment.

Example fix

// before
await _contentManager.CloneAsync(contentItem); // custom handler removed AliasPart from clone
// after
var clone = await _contentManager.CloneAsync(contentItem);
if (!clone.TryGet<AliasPart>(out var aliasPart)) { aliasPart = new AliasPart(); clone.Weld(aliasPart); }
aliasPart.Alias = await _aliasPartHandlerAliasGenerator.GenerateUniqueAliasAsync(...);
Defensive patterns

Strategy: try-catch

Validate before calling

if (!context.CloneContentItem.TryGet<AliasPart>(out _)) { /* re-weld AliasPart before cloning */ }

Type guard

bool CloneHasAliasPart(CloneContentContext ctx) => ctx.CloneContentItem?.TryGet<AliasPart>(out _) == true;

Try / catch

try { await _contentManager.CloneAsync(item); }
catch (InvalidOperationException ex) when (ex.Message.Contains("AliasPart"))
{ _logger.LogError(ex, "Clone lost AliasPart for {Id}", item.ContentItemId); }

Prevention

When it happens

Trigger: 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.

Common situations: Custom clone handlers or workflows modifying CloneContentItem before the driver runs; migrations changing content type definitions; recipes importing items with mismatched part data.

Understand the failure class

Background: "not installed", "pip install", "required for": how missing-dependency errors surface across open-source libraries — this error's family across 34 libraries.

Related errors


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

Appendix: source

Thrown at src/OrchardCore.Modules/OrchardCore.Alias/Handlers/AliasPartHandler.cs:83

    {
        if (context.NoActiveVersionLeft)
        {
            return _tagCache.RemoveTagAsync(AliasConstants.AliasPrefix + instance.Alias);
        }

        return Task.CompletedTask;
    }

    public override Task UnpublishedAsync(PublishContentContext context, AliasPart instance)
    {
        return _tagCache.RemoveTagAsync(AliasConstants.AliasPrefix + instance.Alias);
    }

    public override async Task CloningAsync(CloneContentContext context, AliasPart part)
    {
        if (!context.CloneContentItem.TryGet<AliasPart>(out var clonedPart))
        {
            throw new InvalidOperationException("The cloned content item doesn't contain an AliasPart.");
        }

        clonedPart.Alias = await GenerateUniqueAliasAsync(part.Alias, clonedPart);
        clonedPart.Apply();
    }

    private async Task ComputeAliasAsync(AliasPart part)
    {
        // Compute the Alias only if it's empty.
        if (!string.IsNullOrEmpty(part.Alias))
        {
            return;
        }

        var pattern = await GetPatternAsync(part);

        if (!string.IsNullOrEmpty(pattern))
        {

View on GitHub (pinned to 4306c0717f)