OrchardCMS/OrchardCore · error · NullReferenceException

Content Type does not exist.

Error message

Content Type {contentItem.ContentType} does not exist.

What it means

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.

Solutions

  1. Define the missing content type (recipe step, migration, or admin UI) before displaying items of that type.
  2. Fix the ContentType string on the content item to match an existing definition.
  3. Delete or reassign orphaned content items referencing the removed type.
  4. Re-enable the module/feature that supplies the content type definition.

Example fix

// before
var item = _contentManager.NewAsync("Prodcut").Result; // typo, undefined type
// after
var item = await _contentManager.NewAsync("Product"); // type defined via migration/recipe
Defensive patterns

Strategy: validation

Validate before calling

var def = await _contentDefinitionManager.GetTypeDefinitionAsync(item.ContentType);
if (def == null) throw new InvalidOperationException($"Content type '{item.ContentType}' is not defined; define it before displaying items.");

Type guard

async Task<bool> TypeExistsAsync(IContentDefinitionManager m, string ct) => await m.GetTypeDefinitionAsync(ct) != null;

Try / catch

try { var shape = await displayManager.BuildDisplayAsync(item, null, "Detail", ""); }
catch (NullReferenceException ex) when (ex.Message.Contains("does not exist")) { _logger.LogError(ex, "Undefined content type {Type}", item.ContentType); /* skip or surface friendly error */ }

Prevention

When it happens

Trigger: 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.

Common situations: 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.

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/514079262a97a8d0. Report an issue: GitHub.

Appendix: source

Thrown at src/OrchardCore/OrchardCore.ContentManagement.Display/ContentItemDisplayManager.cs:50

        IShapeFactory shapeFactory,
        IEnumerable<IShapePlacementProvider> placementProviders,
        ILogger<ContentItemDisplayManager> logger,
        ILayoutAccessor layoutAccessor
        ) : base(shapeFactory, placementProviders)
    {
        _handlers = handlers;
        _contentDefinitionManager = contentDefinitionManager;
        _shapeFactory = shapeFactory;
        _layoutAccessor = layoutAccessor;
        _logger = logger;
    }

    public async Task<IShape> BuildDisplayAsync(ContentItem contentItem, IUpdateModel updater, string displayType, string groupId)
    {
        ArgumentNullException.ThrowIfNull(contentItem);

        var contentTypeDefinition = await _contentDefinitionManager.GetTypeDefinitionAsync(contentItem.ContentType)
            ?? throw new NullReferenceException($"Content Type {contentItem.ContentType} does not exist.");

        var actualDisplayType = string.IsNullOrEmpty(displayType) ? OrchardCoreConstants.DisplayType.Detail : displayType;
        var hasStereotype = contentTypeDefinition.TryGetStereotype(out var stereotype);

        var actualShapeType = "Content";

        if (hasStereotype)
        {
            actualShapeType = contentTypeDefinition.GetStereotype();
        }

        // [DisplayType] is only added for the ones different than Detail
        if (actualDisplayType != OrchardCoreConstants.DisplayType.Detail)
        {
            actualShapeType = actualShapeType + "_" + actualDisplayType;
        }

        var itemShape = await CreateContentShapeAsync(actualShapeType);

View on GitHub (pinned to 4306c0717f)