OrchardCMS/OrchardCore · error · ArgumentException
The type must inherit from ContentField
Error message
The type must inherit from ContentField
What it means
GetOrAddContentFieldDisplayOption is the shared helper behind field display option registration; it requires the contentFieldType parameter to be a subclass of ContentField because options are keyed per concrete field type. Passing any other Type (e.g. a ContentPart type or driver type) throws ArgumentException.
Solutions
- Pass the concrete field type, e.g. typeof(TextField) or your class deriving from ContentField.
- If you meant to register a part option, use the ContentPart equivalents (ForContentPartDisplay etc.).
- Create a real ContentField subclass if your data model lacks one.
Example fix
// before options.ForContentFieldEditor(typeof(MyPart), typeof(MyFieldEditor), ...); // after options.ForContentFieldEditor(typeof(MyField), typeof(MyFieldEditor), ...); // MyField : ContentField
Defensive patterns
Strategy: validation
Validate before calling
if (!typeof(ContentField).IsAssignableFrom(fieldType)) throw new ArgumentException($"{fieldType.Name} must inherit from ContentField"); Type guard
bool IsContentFieldType(Type t) => t.IsSubclassOf(typeof(ContentField));
Prevention
- Use typeof(YourConcreteField) — never part or driver types — in field option APIs.
- Verify custom fields derive from ContentField in a module unit test.
- Keep field/part option registrations in clearly separated code blocks.
When it happens
Trigger: Calling ForContentFieldDisplay/ForContentFieldEditor/RemoveContentFieldDisplayDriver (all funnel through GetOrAddContentFieldDisplayOption) with a Type that is not derived from ContentField, such as a part type, a driver type, or object.
Common situations: Swapped generic/Type arguments when wiring a custom field; passing typeof(ContentPart) or the driver's generic parameter by mistake; a custom 'field' implemented as a part instead of a real ContentField subclass.
Understand the failure class
Background: Type mismatch errors: IllegalArgumentException, TypeError and type guards across 150 open-source libraries — this error's family across 150 libraries.
Related errors
- Content Type does not exist.
- Not the latest version.
- Not a draft version.
- The content item is missing a 'ContentItemId'.
- The type must inherit from ContentPart
AI-assisted analysis of OrchardCMS/OrchardCore@4306c0717f (2026-09-13).
Data as JSON: /api/errors/191d4ca582072c01.
Report an issue: GitHub.
Appendix: source
Thrown at src/OrchardCore/OrchardCore.ContentManagement.Display/ContentDisplay/ContentDisplayOptions.cs:106
option.ForEditor(editorDriverType, predicate);
}
internal void RemoveContentFieldDisplayDriver(Type contentPartType, Type driverType)
{
if (!typeof(IContentFieldDisplayDriver).IsAssignableFrom(driverType))
{
throw new ArgumentException("The type must implement " + nameof(IContentFieldDisplayDriver));
}
var option = GetOrAddContentFieldDisplayOption(contentPartType);
option.RemoveDisplayDriver(driverType);
}
private ContentFieldDisplayOption GetOrAddContentFieldDisplayOption(Type contentFieldType)
{
if (!contentFieldType.IsSubclassOf(typeof(ContentField)))
{
throw new ArgumentException("The type must inherit from " + nameof(ContentField));
}
var option = _contentFields.FirstOrDefault(x => x.Type == contentFieldType);
if (option == null)
{
option = new ContentFieldDisplayOption(contentFieldType);
_contentFields.Add(option);
}
return option;
}
}
View on GitHub (pinned to 4306c0717f)