OrchardCMS/OrchardCore · error · ArgumentException

DisplayAsync requires an instance of IShape

Error message

DisplayAsync requires an instance of IShape

What it means

RazorPage.DisplayAsync accepts an object that must be an IShape (or a string that is rendered literally). When the argument is neither a string nor an IShape, the method throws ArgumentException because it has no way to display an arbitrary object. This guards the shape-display pipeline, which resolves templates and drivers by shape type.

Solutions

  1. Wrap the object in a shape before displaying: await DisplayAsync(New.MyShape(Model: myObject))
  2. If the object is content, display it via the item's shape: await DisplayAsync(await Factory.CreateAsync(...)) or use the ContentItem's metadata shape
  3. If you only meant to output text, pass a string, which is rendered as literal HTML
  4. Verify the argument's type implements OrchardCore.DisplayManagement.IShape

Example fix

// before
@await DisplayAsync(Model.MyPart)
// after
@await DisplayAsync(New.MyPartShape(Part: Model.MyPart))
Defensive patterns

Strategy: type-guard

Validate before calling

if (myObject is IShape shape || myObject is string s) { await DisplayAsync(myObject); }

Type guard

bool IsDisplayable(object o) => o is IShape || o is string;

Try / catch

try { await DisplayAsync(candidate); } catch (ArgumentException) { /* fall back to shape wrapping or logging */ }

Prevention

When it happens

Trigger: Calling await DisplayAsync(someModel) in a Razor view where someModel is a plain POCO, dynamic object, ContentItem, or null-shaped object that does not implement IShape and is not a string.

Common situations: Developers pass content-item parts, view models, or results of queries directly to DisplayAsync instead of building a shape (e.g. via New.Shape() or Factory). Also happens after refactoring when a variable that used to be a shape becomes a view model.

Understand the failure class

Background: Type mismatch errors: IllegalArgumentException, TypeError and type guards across 150 open-source libraries — this error's family across 150 libraries.

Related errors


AI-assisted analysis of OrchardCMS/OrchardCore@4306c0717f (2026-09-13). Data as JSON: /api/errors/0564e1f9c21b2ece. Report an issue: GitHub.

Appendix: source

Thrown at src/OrchardCore/OrchardCore.DisplayManagement/Razor/RazorPage.cs:87

    {
        if (shape is IShape s)
        {
            EnsureDisplayHelper();

            return _displayHelper.ShapeExecuteAsync(s);
        }

        if (shape is IHtmlContent hc)
        {
            return Task.FromResult(hc);
        }

        if (shape is string str)
        {
            return Task.FromResult<IHtmlContent>(new HtmlContentString(str));
        }

        throw new ArgumentException("DisplayAsync requires an instance of IShape");
    }

    /// <summary>
    /// Renders a shape.
    /// </summary>
    /// <param name="shape">The shape.</param>
    public Task<IHtmlContent> DisplayAsync(IShape shape)
    {
        EnsureDisplayHelper();

        return _displayHelper.ShapeExecuteAsync(shape);
    }

    /// <summary>
    /// Renders the specified shape by morphing it to the specified type.
    /// </summary>
    /// <param name="shape">The shape to render. Cannot be <see langword="null"/>.</param>
    /// <param name="shapeType">The shape type to assign to the shape before rendering.</param>

View on GitHub (pinned to 4306c0717f)