OrchardCMS/OrchardCore · error · InvalidOperationException
The ' ' field in ' ' part was defined without a specified…
Error message
The '{field.Name}' field in '{model.Name}' part was defined without a specified type. Please review the migration and explicitly specify the field type. What it means
During content definition migrations, adding a field to a part requires an explicit FieldDefinition (the field type). When a migration adds a field whose type was not specified, ContentDefinitionManager.Apply throws to prevent persisting a field record with no type, which would break rendering and querying later.
Solutions
- Add .WithFieldType<TField>() (e.g., TextField, BooleanField) to the field definition in the migration
- Review the migration code and specify the field type explicitly for every field
- Fix data that produced a null FieldDefinition if fields are built dynamically
Example fix
// before
_builder.WithPart("MyPart", p => p.WithField("Count", f => f.OfType(null)));
// after
_builder.WithPart("MyPart", p => p.WithField("Count", f => f.OfType("NumberField"))); Defensive patterns
Strategy: validation
Validate before calling
foreach (var f in part.Fields) { if (f.FieldDefinition is null) throw new InvalidOperationException($"Field '{f.Name}' needs WithFieldType in the migration."); } Type guard
bool hasType = migrationField.FieldDefinition is not null;
Try / catch
try { await _contentDefinitionManager.ApplyMigrationsAsync(); } catch (InvalidOperationException ex) when (ex.Message.Contains("without a specified type")) { /* fix migration code */ } Prevention
- Always chain .WithFieldType/OfType on every migration field
- Test migrations on a fresh site
- Review copy-pasted migration snippets for missing type calls
When it happens
Trigger: Calling BuildPart/WithField in a migration step without chaining .WithFieldType<T> or providing the field definition, then Apply()-ing the migration.
Common situations: Copy-pasted migration code missing the field type call; refactored migrations after upgrading where field-type APIs changed; dynamically constructed field definitions that left FieldDefinition null.
Understand the failure class
Background: "missing required argument" and "the following required arguments were not provided": what required-argument errors mean and how to fix them — this error's family across 20 libraries.
Related errors
- Invalid return type used in a migration method.
- Unable to create a unique index name for
- The 'fieldName' can't be null or empty.
- Unable to remove system-defined field.
- The part doesn't exist
AI-assisted analysis of OrchardCMS/OrchardCore@4306c0717f (2026-09-13).
Data as JSON: /api/errors/254403c35a68a40e.
Report an issue: GitHub.
Appendix: source
Thrown at src/OrchardCore/OrchardCore.ContentManagement/ContentDefinitionManager.cs:319
.Where(partFieldDefinitionRecord => !model.Fields
.Any(partField => partField.Name.EqualsOrdinalIgnoreCase(partFieldDefinitionRecord.Name)))
.ToArray();
foreach (var remove in toRemove)
{
record.ContentPartFieldDefinitionRecords.Remove(remove);
}
foreach (var field in model.Fields)
{
var partFieldRecord = record.ContentPartFieldDefinitionRecords
.FirstOrDefault(partField => partField.Name.EqualsOrdinalIgnoreCase(field.Name));
if (partFieldRecord is null)
{
if (field.FieldDefinition is null)
{
throw new InvalidOperationException(
$"The '{field.Name}' field in '{model.Name}' part was defined without a specified type." +
" Please review the migration and explicitly specify the field type.");
}
partFieldRecord = new ContentPartFieldDefinitionRecord
{
FieldName = field.FieldDefinition.Name,
Name = field.Name,
};
record.ContentPartFieldDefinitionRecords.Add(partFieldRecord);
}
Apply(field, partFieldRecord);
}
}
private static void Apply(ContentPartFieldDefinition model, ContentPartFieldDefinitionRecord record)View on GitHub (pinned to 4306c0717f)