OrchardCMS/OrchardCore · error · ArgumentException

The part doesn't exist

Error message

The part doesn't exist: {partName}

What it means

GenerateFieldNameFromDisplayNameAsync resolves the container for the new field name: it loads a part definition, and if none exists, falls back to a type definition. If neither a part nor a type with the given name exists, it throws an ArgumentException stating the part doesn't exist.

Solutions

  1. Verify the part or type exists via IContentDefinitionManager.LoadPartDefinitionAsync / LoadTypeDefinitionAsync before calling.
  2. Fix the spelling/casing of partName to match the stored definition name.
  3. Create the part (AlterPartDefinitionAsync) or attach the type part first if you intend to add a field to a not-yet-existing container.

Example fix

// before
var fieldName = await service.GenerateFieldNameFromDisplayNameAsync("My Field", "ProductPart");
// after
if (await contentDefinitionManager.LoadPartDefinitionAsync("ProductPart") is null
    && await contentDefinitionManager.LoadTypeDefinitionAsync("ProductPart") is null)
{
    throw new InvalidOperationException("Create ProductPart before generating field names for it.");
}
var fieldName = await service.GenerateFieldNameFromDisplayNameAsync("My Field", "ProductPart");
Defensive patterns

Strategy: validation

Validate before calling

// C#
var part = await contentDefinitionManager.LoadPartDefinitionAsync(partName);
var type = part is null ? await contentDefinitionManager.LoadTypeDefinitionAsync(partName) : null;
if (part is null && type is null)
    throw new ArgumentException($"The part doesn't exist: {partName}");

Type guard

async Task<bool> ContainerExistsAsync(IContentDefinitionManager mgr, string name) =>
    await mgr.LoadPartDefinitionAsync(name) is not null
    || await mgr.LoadTypeDefinitionAsync(name) is not null;

Try / catch

try
{
    var fieldName = await service.GenerateFieldNameFromDisplayNameAsync(displayName, partName);
}
catch (ArgumentException ex)
{
    logger.LogWarning(ex, "No part or type named {PartName}", partName);
}

Prevention

When it happens

Trigger: Calling GenerateFieldNameFromDisplayNameAsync(displayName, partName) with a partName that matches neither a part definition nor a type definition — e.g. a typo, an unsaved/not-yet-created part, or a type name after it was renamed or removed.

Common situations: Generating field names in custom admin tooling or editor JS-backed endpoints before the part/type was persisted; case-sensitivity mismatches with the stored definition name.

Understand the failure class

Background: "Not found" and "does not exist" errors: why "Task not found", "No such folder", and "Can't find" fire when a lookup comes back empty — this error's family across 14 libraries.

Related errors


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

Appendix: source

Thrown at src/OrchardCore.Modules/OrchardCore.ContentTypes/Services/ContentDefinitionService.cs:456

        while (await _contentDefinitionManager.LoadTypeDefinitionAsync(displayName) != null)
        {
            displayName = VersionName(displayName);
        }

        return displayName;
    }

    public async Task<string> GenerateFieldNameFromDisplayNameAsync(string partName, string displayName)
    {
        IEnumerable<ContentPartFieldDefinition> fieldDefinitions;

        var part = await _contentDefinitionManager.LoadPartDefinitionAsync(partName);
        displayName = displayName.ToSafeName();

        if (part == null)
        {
            var type = await _contentDefinitionManager.LoadTypeDefinitionAsync(partName)
                ?? throw new ArgumentException("The part doesn't exist: " + partName);

            var typePart = type.Parts?.FirstOrDefault(x => x.PartDefinition.Name == partName);

            // If passed in might be that of a type w/ no implicit field.
            if (typePart == null)
            {
                return displayName;
            }

            fieldDefinitions = typePart.PartDefinition.Fields.ToList();
        }
        else
        {
            fieldDefinitions = part.Fields.ToList();
        }

        while (fieldDefinitions.Any(x => string.Equals(displayName.Trim(), x.Name.Trim(), StringComparison.OrdinalIgnoreCase)))
        {

View on GitHub (pinned to 4306c0717f)