OrchardCMS/OrchardCore · error · InvalidOperationException

The cloned content item doesn't contain a LocalizationPart.

Error message

The cloned content item doesn't contain a LocalizationPart.

What it means

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.

Solutions

  1. Ensure LocalizationPart is attached to the content type before cloning.
  2. Use standard IContentManager clone flows that copy all parts.
  3. Weld a LocalizationPart onto the clone item before invoking the clone pipeline.
  4. Migrate legacy items so the part is present in both definition and item data.

Example fix

// before
var clone = new ContentItem { ContentType = item.ContentType };
await _contentManager.CloneAsync(item);
// after
var clone = item.Clone();
clone.Weld(new LocalizationPart());
await _contentManager.CreateAsync(clone);
Defensive patterns

Strategy: validation

Validate before calling

if (!context.CloneContentItem.TryGet<LocalizationPart>(out _)) throw new InvalidOperationException("Clone must carry LocalizationPart before cloning.");

Type guard

static bool HasLocalization(ContentItem item) => item.TryGet<LocalizationPart>(out _);

Try / catch

try { await _contentManager.CloneAsync(item); }
catch (InvalidOperationException ex) when (ex.Message.Contains("LocalizationPart"))
{
    logger.LogError(ex, "Clone of {Id} lacks LocalizationPart", item.ContentItemId);
    throw;
}

Prevention

When it happens

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

Common situations: 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.

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/0984ed01f2c48d26. Report an issue: GitHub.

Appendix: source

Thrown at src/OrchardCore.Modules/OrchardCore.ContentLocalization/Handlers/LocalizationPartHandler.cs:95

        return Task.CompletedTask;
    }

    public override Task RemovedAsync(RemoveContentContext context, LocalizationPart part)
    {
        if (!string.IsNullOrWhiteSpace(part.LocalizationSet) && part.Culture != null && context.NoActiveVersionLeft)
        {
            // Update entries from the index table after the session is committed.
            return _entries.UpdateEntriesAsync();
        }

        return Task.CompletedTask;
    }

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

        clonedPart.LocalizationSet = string.Empty;
        clonedPart.Apply();
        return Task.CompletedTask;
    }
}

View on GitHub (pinned to 4306c0717f)