{"record":{"id":"ea91410b797a02e8","repo":"OrchardCMS/OrchardCore","slug":"the-part-doesn-t-exist-partname","errorCode":null,"errorMessage":"The part doesn't exist: {partName}","messagePattern":"The part doesn't exist: (.+?)","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"src/OrchardCore.Modules/OrchardCore.ContentTypes/Services/ContentDefinitionService.cs","lineNumber":456,"sourceCode":"        while (await _contentDefinitionManager.LoadTypeDefinitionAsync(displayName) != null)\n        {\n            displayName = VersionName(displayName);\n        }\n\n        return displayName;\n    }\n\n    public async Task<string> GenerateFieldNameFromDisplayNameAsync(string partName, string displayName)\n    {\n        IEnumerable<ContentPartFieldDefinition> fieldDefinitions;\n\n        var part = await _contentDefinitionManager.LoadPartDefinitionAsync(partName);\n        displayName = displayName.ToSafeName();\n\n        if (part == null)\n        {\n            var type = await _contentDefinitionManager.LoadTypeDefinitionAsync(partName)\n                ?? throw new ArgumentException(\"The part doesn't exist: \" + partName);\n\n            var typePart = type.Parts?.FirstOrDefault(x => x.PartDefinition.Name == partName);\n\n            // If passed in might be that of a type w/ no implicit field.\n            if (typePart == null)\n            {\n                return displayName;\n            }\n\n            fieldDefinitions = typePart.PartDefinition.Fields.ToList();\n        }\n        else\n        {\n            fieldDefinitions = part.Fields.ToList();\n        }\n\n        while (fieldDefinitions.Any(x => string.Equals(displayName.Trim(), x.Name.Trim(), StringComparison.OrdinalIgnoreCase)))\n        {","sourceCodeStart":438,"sourceCodeEnd":474,"githubUrl":"https://github.com/OrchardCMS/OrchardCore/blob/4306c0717fe573f6fca1b4955909ddab6a192807/src/OrchardCore.Modules/OrchardCore.ContentTypes/Services/ContentDefinitionService.cs#L438-L474","documentation":"GenerateFieldNameFromDisplayNameAsync resolves the container for the new field name: it loads a part definition, and if none exists, falls back to a type definition. If neither a part nor a type with the given name exists, it throws an ArgumentException stating the part doesn't exist.","triggerScenarios":"Calling GenerateFieldNameFromDisplayNameAsync(displayName, partName) with a partName that matches neither a part definition nor a type definition — e.g. a typo, an unsaved/not-yet-created part, or a type name after it was renamed or removed.","commonSituations":"Generating field names in custom admin tooling or editor JS-backed endpoints before the part/type was persisted; case-sensitivity mismatches with the stored definition name.","solutions":["Verify the part or type exists via IContentDefinitionManager.LoadPartDefinitionAsync / LoadTypeDefinitionAsync before calling.","Fix the spelling/casing of partName to match the stored definition name.","Create the part (AlterPartDefinitionAsync) or attach the type part first if you intend to add a field to a not-yet-existing container."],"exampleFix":"// before\nvar fieldName = await service.GenerateFieldNameFromDisplayNameAsync(\"My Field\", \"ProductPart\");\n// after\nif (await contentDefinitionManager.LoadPartDefinitionAsync(\"ProductPart\") is null\n    && await contentDefinitionManager.LoadTypeDefinitionAsync(\"ProductPart\") is null)\n{\n    throw new InvalidOperationException(\"Create ProductPart before generating field names for it.\");\n}\nvar fieldName = await service.GenerateFieldNameFromDisplayNameAsync(\"My Field\", \"ProductPart\");","handlingStrategy":"validation","validationCode":"// C#\nvar part = await contentDefinitionManager.LoadPartDefinitionAsync(partName);\nvar type = part is null ? await contentDefinitionManager.LoadTypeDefinitionAsync(partName) : null;\nif (part is null && type is null)\n    throw new ArgumentException($\"The part doesn't exist: {partName}\");","typeGuard":"async Task<bool> ContainerExistsAsync(IContentDefinitionManager mgr, string name) =>\n    await mgr.LoadPartDefinitionAsync(name) is not null\n    || await mgr.LoadTypeDefinitionAsync(name) is not null;","tryCatchPattern":"try\n{\n    var fieldName = await service.GenerateFieldNameFromDisplayNameAsync(displayName, partName);\n}\ncatch (ArgumentException ex)\n{\n    logger.LogWarning(ex, \"No part or type named {PartName}\", partName);\n}","preventionTips":["Ensure the part/type is created before generating field names for it.","Verify spelling and casing against the stored definition name.","Use LoadPartDefinitionAsync/LoadTypeDefinitionAsync as a pre-check in tooling."],"tags":["contenttypes","entity-not-found","fields"],"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-16T04:17:20.429Z"}