{"record":{"id":"c75c976d942411e0","repo":"OrchardCMS/OrchardCore","slug":"displayasync-requires-an-instance-of-ishape-page","errorCode":null,"errorMessage":"DisplayAsync requires an instance of IShape","messagePattern":"DisplayAsync requires an instance of IShape","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"src/OrchardCore/OrchardCore.DisplayManagement/RazorPages/Page.cs","lineNumber":83,"sourceCode":"    public Task<IHtmlContent> DisplayAsync(dynamic shape)\n    {\n        if (shape is IShape s)\n        {\n            EnsureDisplayHelper();\n            return _displayHelper.ShapeExecuteAsync(s);\n        }\n\n        if (shape is IHtmlContent hc)\n        {\n            return Task.FromResult(hc);\n        }\n\n        if (shape is string str)\n        {\n            return Task.FromResult<IHtmlContent>(new HtmlContentString(str));\n        }\n\n        throw new ArgumentException(\"DisplayAsync requires an instance of IShape\");\n    }\n\n    /// <summary>\n    /// Renders a shape.\n    /// </summary>\n    /// <param name=\"shape\">The shape.</param>\n    public Task<IHtmlContent> DisplayAsync(IShape shape)\n    {\n        EnsureDisplayHelper();\n        return _displayHelper.ShapeExecuteAsync(shape);\n    }\n\n    public IOrchardDisplayHelper Orchard\n    {\n        get\n        {\n            if (_orchardHelper == null)\n            {","sourceCodeStart":65,"sourceCodeEnd":101,"githubUrl":"https://github.com/OrchardCMS/OrchardCore/blob/4306c0717fe573f6fca1b4955909ddab6a192807/src/OrchardCore/OrchardCore.DisplayManagement/RazorPages/Page.cs#L65-L101","documentation":"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.","triggerScenarios":"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.","commonSituations":"Porting Razor view code into Razor Pages and passing page Model directly; passing service-returned DTOs to DisplayAsync; assuming dynamic objects are shapes.","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"],"exampleFix":"// before\n@await DisplayAsync(Model)\n// after\n@await DisplayAsync(New.Summary(Model: Model.ContentItem))","handlingStrategy":"type-guard","validationCode":"if (obj is IShape || obj is string) { await DisplayAsync(obj); }","typeGuard":"bool CanDisplay(object o) => o is IShape || o is string;","tryCatchPattern":"try { await DisplayAsync(candidate); } catch (ArgumentException) { candidate = New.Fallback(Model: candidate); await DisplayAsync(candidate); }","preventionTips":["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"],"tags":["razor-pages","shapes","type-mismatch","display-management"],"backgroundTag":"type-mismatch","analyzedSha":"4306c0717fe573f6fca1b4955909ddab6a192807","analyzedAt":"2026-09-13T17:41:05.024Z","contentChangedAt":"2026-09-13T17:41:05.024Z","schemaVersion":2},"datasetVersion":"2026-09-16T04:17:20.429Z"}