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
- Build a shape: await DisplayAsync(New.MyShape(Model: myObject))
- Pass a string if only literal HTML/text output is intended
- For content items, get and display their shape instead of the raw item
- 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
- In Razor Pages, build shapes via New.<Name>() instead of passing the Page Model directly
- Display content items through their generated shapes
- Keep a helper that narrows objects before display
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
- DisplayAsync requires an instance of IShape
- AlternateCollection can't be changed.
- Unexpected token type
- Unexpected token parsing TimeSpan. Expected a string, got
- The type must implement IContentPartDisplayDriver
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)