{"record":{"id":"efb8037aec26fd22","repo":"OrchardCMS/OrchardCore","slug":"the-content-part-context-contentpartfielddefinition","errorCode":null,"errorMessage":"The content part '{context.ContentPartFieldDefinition.ContentTypePartDefinition.Name}' could not be found.","messagePattern":"The content part '(.+?)' could not be found\\.","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"src/OrchardCore.Modules/OrchardCore.ContentFields/Handlers/TextFieldHandler.cs","lineNumber":79,"sourceCode":"        // Do not compute the title if the user can modify it.\n        if (settings is null || settings.Type == FieldBehaviorType.Editable)\n        {\n            return;\n        }\n\n        if (!string.IsNullOrEmpty(settings.Pattern))\n        {\n            var value = await _liquidTemplateManager.RenderStringAsync(settings.Pattern, NullEncoder.Default, field,\n                new Dictionary<string, FluidValue>()\n                {\n                    [\"ContentItem\"] = new ObjectValue(field.ContentItem),\n                });\n\n            field.Text = value?.Trim();\n\n            var partActivator = _contentPartFactory.GetTypeActivator(context.PartName);\n            var part = (field.ContentItem.Get(partActivator.Type, context.ContentPartFieldDefinition.ContentTypePartDefinition.Name) as ContentPart)\n                ?? throw new InvalidOperationException($\"The content part '{context.ContentPartFieldDefinition.ContentTypePartDefinition.Name}' could not be found.\");\n\n            part.Apply(context.ContentPartFieldDefinition.Name, field);\n        }\n    }\n}\n","sourceCodeStart":61,"sourceCodeEnd":85,"githubUrl":"https://github.com/OrchardCMS/OrchardCore/blob/4306c0717fe573f6fca1b4955909ddab6a192807/src/OrchardCore.Modules/OrchardCore.ContentFields/Handlers/TextFieldHandler.cs#L61-L85","documentation":"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.","triggerScenarios":"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).","commonSituations":"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.","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."],"exampleFix":"// before\nvar part = field.ContentItem.Get<MyPart>(\"OldPartName\"); // null -> throws\n// after\nvar part = field.ContentItem.GetOrCreate<MyPart>(\"CorrectPartName\");","handlingStrategy":"validation","validationCode":"var partName = context.ContentPartFieldDefinition.ContentTypePartDefinition.Name;\nif (field.ContentItem.Get<ContentPart>(partName) is null)\n    throw new InvalidOperationException($\"Part '{partName}' missing on item {field.ContentItem.ContentItemId}\");","typeGuard":"static bool HasPart(ContentItem item, string partName) => item.Get<ContentPart>(partName) is not null;","tryCatchPattern":"try { await handler.SetValueAsync(model, updater, ctx); }\ncatch (InvalidOperationException ex) when (ex.Message.Contains(\"could not be found\"))\n{\n    logger.LogError(ex, \"Field update skipped: owning part missing\");\n    updater.ModelState.AddModelError(\"\", \"The content part for this field no longer exists on the item.\");\n}","preventionTips":["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"],"tags":["contentfields","textfield","content-parts"],"backgroundTag":"entity-not-found","analyzedSha":"4306c0717fe573f6fca1b4955909ddab6a192807","analyzedAt":"2026-09-13T17:41:05.024Z","contentChangedAt":"2026-09-13T17:41:05.024Z","schemaVersion":2},"datasetVersion":"2026-09-15T23:17:13.987Z"}