OrchardCMS/OrchardCore · error · InvalidOperationException
The content part ' ' could not be found.
Error message
The content part '{context.ContentPartFieldDefinition.ContentTypePartDefinition.Name}' could not be found. What it means
TextFieldHandler.SetValueAsync applies a submitted field value to the field's ContentItem by locating the owning content part via its part name. If the ContentItem does not contain a part with the given name, it throws InvalidOperationException. The part type is activated through IContentPartFactory, but the stored item must already hold an instance under that exact part name.
Solutions
- Re-add the missing content part to the content type definition so the item gets the part when loaded.
- Verify the part name in ContentTypePartDefinition matches the part actually attached to the item.
- Use GetOrCreate<PartType>(partName) in custom code before setting field values.
- Write a migration to patch existing content items that lack the part.
Example fix
// before
var part = field.ContentItem.Get<MyPart>("OldPartName"); // null -> throws
// after
var part = field.ContentItem.GetOrCreate<MyPart>("CorrectPartName"); Defensive patterns
Strategy: validation
Validate before calling
var partName = context.ContentPartFieldDefinition.ContentTypePartDefinition.Name;
if (field.ContentItem.Get<ContentPart>(partName) is null)
throw new InvalidOperationException($"Part '{partName}' missing on item {field.ContentItem.ContentItemId}"); Type guard
static bool HasPart(ContentItem item, string partName) => item.Get<ContentPart>(partName) is not null;
Try / catch
try { await handler.SetValueAsync(model, updater, ctx); }
catch (InvalidOperationException ex) when (ex.Message.Contains("could not be found"))
{
logger.LogError(ex, "Field update skipped: owning part missing");
updater.ModelState.AddModelError("", "The content part for this field no longer exists on the item.");
} Prevention
- Never remove a part from a type without migrating existing items
- Keep part names stable; renaming changes the stored key
- Use GetOrCreate<TPart>(name) in custom field-writing code
- Validate imported items contain all parts defined by their type
When it happens
Trigger: Editing/creating/cloning content where the driver submits a TextField value but the content item's parts were removed or renamed (e.g. part removed from the type definition, part name changed, or item built without Welding the part).
Common situations: Content type definitions changed after items were created; custom code creating content items without attaching the part; a typo or casing mismatch in the part name in placement/editor settings; importing items missing parts.
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/efb8037aec26fd22.
Report an issue: GitHub.
Appendix: source
Thrown at src/OrchardCore.Modules/OrchardCore.ContentFields/Handlers/TextFieldHandler.cs:79
// Do not compute the title if the user can modify it.
if (settings is null || settings.Type == FieldBehaviorType.Editable)
{
return;
}
if (!string.IsNullOrEmpty(settings.Pattern))
{
var value = await _liquidTemplateManager.RenderStringAsync(settings.Pattern, NullEncoder.Default, field,
new Dictionary<string, FluidValue>()
{
["ContentItem"] = new ObjectValue(field.ContentItem),
});
field.Text = value?.Trim();
var partActivator = _contentPartFactory.GetTypeActivator(context.PartName);
var part = (field.ContentItem.Get(partActivator.Type, context.ContentPartFieldDefinition.ContentTypePartDefinition.Name) as ContentPart)
?? throw new InvalidOperationException($"The content part '{context.ContentPartFieldDefinition.ContentTypePartDefinition.Name}' could not be found.");
part.Apply(context.ContentPartFieldDefinition.Name, field);
}
}
}
View on GitHub (pinned to 4306c0717f)