OrchardCMS/OrchardCore · error · ArgumentException

DisplayAsync requires an instance of IShape

Error message

DisplayAsync requires an instance of IShape

What it means

The Razor Pages equivalent of RazorPage.DisplayAsync: Page.DisplayAsync requires the argument to be an IShape (strings are emitted literally). Any other object cannot be rendered by the shape pipeline, so an ArgumentException is thrown. This keeps shape rendering type-safe in Razor Pages.

Solutions

  1. Build a shape: await DisplayAsync(New.MyShape(Model: myObject))
  2. Pass a string if only literal HTML/text output is intended
  3. For content items, get and display their shape instead of the raw item
  4. Confirm the argument implements OrchardCore.DisplayManagement.IShape

Example fix

// before
@await DisplayAsync(Model)
// after
@await DisplayAsync(New.Summary(Model: Model.ContentItem))
Defensive patterns

Strategy: type-guard

Validate before calling

if (obj is IShape || obj is string) { await DisplayAsync(obj); }

Type guard

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

Try / catch

try { await DisplayAsync(candidate); } catch (ArgumentException) { candidate = New.Fallback(Model: candidate); await DisplayAsync(candidate); }

Prevention

When it happens

Trigger: Calling await DisplayAsync(obj) from a Razor Page (Page base class) where obj is not IShape and not a string — e.g. passing a view model, ContentItem, or dynamic wrapper.

Common situations: Porting Razor view code into Razor Pages and passing page Model directly; passing service-returned DTOs to DisplayAsync; assuming dynamic objects are shapes.

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

Appendix: source

Thrown at src/OrchardCore/OrchardCore.DisplayManagement/RazorPages/Page.cs:83

    public Task<IHtmlContent> DisplayAsync(dynamic shape)
    {
        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);
    }

    public IOrchardDisplayHelper Orchard
    {
        get
        {
            if (_orchardHelper == null)
            {

View on GitHub (pinned to 4306c0717f)