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

  1. Add .WithFieldType<TField>() (e.g., TextField, BooleanField) to the field definition in the migration
  2. Review the migration code and specify the field type explicitly for every field
  3. 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

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


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)