{"record":{"id":"514079262a97a8d0","repo":"OrchardCMS/OrchardCore","slug":"content-type-contentitem-contenttype-does-not-exist","errorCode":null,"errorMessage":"Content Type {contentItem.ContentType} does not exist.","messagePattern":"Content Type (.+?) does not exist\\.","errorType":"exception","errorClass":"NullReferenceException","httpStatus":null,"severity":"error","filePath":"src/OrchardCore/OrchardCore.ContentManagement.Display/ContentItemDisplayManager.cs","lineNumber":50,"sourceCode":"        IShapeFactory shapeFactory,\n        IEnumerable<IShapePlacementProvider> placementProviders,\n        ILogger<ContentItemDisplayManager> logger,\n        ILayoutAccessor layoutAccessor\n        ) : base(shapeFactory, placementProviders)\n    {\n        _handlers = handlers;\n        _contentDefinitionManager = contentDefinitionManager;\n        _shapeFactory = shapeFactory;\n        _layoutAccessor = layoutAccessor;\n        _logger = logger;\n    }\n\n    public async Task<IShape> BuildDisplayAsync(ContentItem contentItem, IUpdateModel updater, string displayType, string groupId)\n    {\n        ArgumentNullException.ThrowIfNull(contentItem);\n\n        var contentTypeDefinition = await _contentDefinitionManager.GetTypeDefinitionAsync(contentItem.ContentType)\n            ?? throw new NullReferenceException($\"Content Type {contentItem.ContentType} does not exist.\");\n\n        var actualDisplayType = string.IsNullOrEmpty(displayType) ? OrchardCoreConstants.DisplayType.Detail : displayType;\n        var hasStereotype = contentTypeDefinition.TryGetStereotype(out var stereotype);\n\n        var actualShapeType = \"Content\";\n\n        if (hasStereotype)\n        {\n            actualShapeType = contentTypeDefinition.GetStereotype();\n        }\n\n        // [DisplayType] is only added for the ones different than Detail\n        if (actualDisplayType != OrchardCoreConstants.DisplayType.Detail)\n        {\n            actualShapeType = actualShapeType + \"_\" + actualDisplayType;\n        }\n\n        var itemShape = await CreateContentShapeAsync(actualShapeType);","sourceCodeStart":32,"sourceCodeEnd":68,"githubUrl":"https://github.com/OrchardCMS/OrchardCore/blob/4306c0717fe573f6fca1b4955909ddab6a192807/src/OrchardCore/OrchardCore.ContentManagement.Display/ContentItemDisplayManager.cs#L32-L68","documentation":"ContentItemDisplayManager.BuildDisplayAsync resolves the content type definition via IContentDefinitionManager.GetTypeDefinitionAsync before building the display shape. If the content item's ContentType has no definition (the type was never declared or was deleted), a NullReferenceException naming the missing type is thrown instead of silently rendering nothing.","triggerScenarios":"Calling BuildDisplayAsync with a ContentItem whose ContentType string does not match any defined content type — e.g. after the type was removed from a recipe/migration, a typo in ContentType, or importing content from another site with types that were never created.","commonSituations":"Deleting a content type in admin while items of that type remain; recipes/migrations that create content items before defining their type; renamed types across deployments; tenants where the defining feature is disabled.","solutions":["Define the missing content type (recipe step, migration, or admin UI) before displaying items of that type.","Fix the ContentType string on the content item to match an existing definition.","Delete or reassign orphaned content items referencing the removed type.","Re-enable the module/feature that supplies the content type definition."],"exampleFix":"// before\nvar item = _contentManager.NewAsync(\"Prodcut\").Result; // typo, undefined type\n// after\nvar item = await _contentManager.NewAsync(\"Product\"); // type defined via migration/recipe","handlingStrategy":"validation","validationCode":"var def = await _contentDefinitionManager.GetTypeDefinitionAsync(item.ContentType);\nif (def == null) throw new InvalidOperationException($\"Content type '{item.ContentType}' is not defined; define it before displaying items.\");","typeGuard":"async Task<bool> TypeExistsAsync(IContentDefinitionManager m, string ct) => await m.GetTypeDefinitionAsync(ct) != null;","tryCatchPattern":"try { var shape = await displayManager.BuildDisplayAsync(item, null, \"Detail\", \"\"); }\ncatch (NullReferenceException ex) when (ex.Message.Contains(\"does not exist\")) { _logger.LogError(ex, \"Undefined content type {Type}\", item.ContentType); /* skip or surface friendly error */ }","preventionTips":["Never hardcode ContentType strings; use constants or load from definitions.","Ensure recipes/migrations define types before importing items of them.","Audit for orphaned items after deleting content types in admin.","Wrap display building of arbitrary items in try/catch in listing pages."],"tags":["csharp","content-management","null-reference","content-type"],"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"}