OrchardCMS/OrchardCore · error · InvalidOperationException

Unable to remove system-defined type.

Error message

Unable to remove system-defined type.

What it means

RemoveTypeAsync checks the target type's ContentSettings and throws InvalidOperationException if IsSystemDefined is true. System-defined types (declared by modules/features) are considered infrastructure and must not be deleted through the content definition API.

Solutions

  1. Check typeDefinition.GetSettings<ContentSettings>().IsSystemDefined before calling RemoveTypeAsync and skip such types.
  2. If the type truly must not exist, disable the feature/module that declares it instead of deleting its definition.
  3. Remove the IsSystemDefined flag only if you own the definition and understand the consequences (via an editor or migration), then remove it.

Example fix

// before
await contentDefinitionService.RemoveTypeAsync("User");
// after
var def = await contentDefinitionManager.LoadTypeDefinitionAsync("User");
if (def?.GetSettings<ContentSettings>().IsSystemDefined != true)
{
    await contentDefinitionService.RemoveTypeAsync("User");
}
Defensive patterns

Strategy: validation

Validate before calling

// C#
var def = await contentDefinitionManager.LoadTypeDefinitionAsync(typeName);
bool removable = def is not null && !def.GetSettings<ContentSettings>().IsSystemDefined;

Type guard

static bool IsRemovable(TypeDefinition def) =>
    def is not null && !def.GetSettings<ContentSettings>().IsSystemDefined;

Try / catch

try
{
    await contentDefinitionService.RemoveTypeAsync(typeName);
}
catch (InvalidOperationException)
{
    // skip or surface: type is system-defined
}

Prevention

When it happens

Trigger: Calling IContentDefinitionService.RemoveTypeAsync(name) on a type whose settings have IsSystemDefined=true, e.g. built-in types like User or types marked system-defined via ContentSettings.

Common situations: Trying to 'clean up' built-in content types via a migration, recipe step, or admin-less code path; deleting all types in a loop without skipping system ones.

Understand the failure class

Background: UnsupportedOperationException and "is not supported" errors: when a library deliberately refuses a call — this error's family across 30 libraries.

Related errors


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

Appendix: source

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

        return contentTypeDefinition;
    }

    public async Task RemoveTypeAsync(string name, bool deleteContent)
    {
        // First remove all attached parts.
        var typeDefinition = await _contentDefinitionManager.LoadTypeDefinitionAsync(name);

        if (typeDefinition == null)
        {
            return;
        }

        var settings = typeDefinition.GetSettings<ContentSettings>();

        if (settings.IsSystemDefined)
        {
            throw new InvalidOperationException("Unable to remove system-defined type.");
        }

        var partDefinitions = typeDefinition.Parts.ToList();
        foreach (var partDefinition in partDefinitions)
        {
            await RemovePartFromTypeAsync(partDefinition.PartDefinition.Name, name);

            // Delete the part if it's its own part.
            if (partDefinition.PartDefinition.Name == name)
            {
                await RemovePartAsync(name);
            }
        }

        await _contentDefinitionManager.DeleteTypeDefinitionAsync(name);

        var context = new ContentTypeRemovedContext
        {

View on GitHub (pinned to 4306c0717f)