{"record":{"id":"b118ed2b935e2909","repo":"OrchardCMS/OrchardCore","slug":"fatal-error-a-layout-couldn-t-be-created","errorCode":null,"errorMessage":"Fatal error, a Layout couldn't be created.","messagePattern":"Fatal error, a Layout couldn't be created\\.","errorType":"exception","errorClass":"ApplicationException","httpStatus":null,"severity":"critical","filePath":"src/OrchardCore/OrchardCore.DisplayManagement/Layout/LayoutAccessor.cs","lineNumber":47,"sourceCode":"        return GetLayoutInternalAsync();\n    }\n\n    private async Task<IZoneHolding> GetLayoutInternalAsync()\n    {\n        // Create a shape whose properties are dynamically created as Zone shapes.\n        var layout = await _shapeFactory.CreateAsync(\n            \"Layout\",\n            static (shapeFactory) =>\n                ValueTask.FromResult<IShape>(\n                    new ZoneHolding<IShapeFactory>(\n                        static (factory) => factory.CreateAsync(\"Zone\"),\n                        shapeFactory)),\n            _shapeFactory) as IZoneHolding;\n\n        if (layout == null)\n        {\n            // At this point a Layout shape should always exist.\n            throw new ApplicationException(\"Fatal error, a Layout couldn't be created.\");\n        }\n\n        _layout = Task.FromResult(layout);\n        return layout;\n    }\n}\n","sourceCodeStart":29,"sourceCodeEnd":54,"githubUrl":"https://github.com/OrchardCMS/OrchardCore/blob/4306c0717fe573f6fca1b4955909ddab6a192807/src/OrchardCore/OrchardCore.DisplayManagement/Layout/LayoutAccessor.cs#L29-L54","documentation":"LayoutAccessor.GetLayoutInternalAsync builds the Layout shape and casts it to IZoneHolding. If the created layout is null — the shape factory produced no Layout shape, which should never happen in a correctly configured site — it throws ApplicationException(\"Fatal error, a Layout couldn't be created.\"). This is an internal invariant guard during page rendering.","triggerScenarios":"Requesting the layout (GetLayoutAsync) on a tenant where the 'Layout' shape cannot be created — e.g., the theme's layout binding/factory missing, shape creation returning null, or theme modules disabled.","commonSituations":"Broken or partially disabled theme that no longer defines the Layout shape; errors earlier in shape creation (see DefaultShapeFactory null creation); recipes/themes switched so no active theme provides a layout; startup DI failures swallowed earlier.","solutions":["Enable a theme that provides a Layout shape (e.g., via admin or by fixing the tenant's current theme setting).","Fix the underlying shape creation failure — check logs for the earlier exception (often a null shape factory result for 'Layout').","Verify IShapeFactory and display infrastructure are correctly registered and the request is running inside a tenant shell scope, not root."],"exampleFix":"// before (tenant settings)\n\"CurrentTheme\": \"MyBrokenTheme\"\n// after — re-enable a working theme\nservices.TryAddScoped<IThemeSelector, DefaultThemeSelector>(); // or reset theme in admin: Themes -> set 'TheTheme'","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"catch (ApplicationException ex) when (ex.Message.Contains(\"Layout couldn't be created\"))\n{\n    logger.LogCritical(ex, \"Layout shape missing; check active theme and shape factory\");\n    throw; // rendering cannot continue without a layout\n}","preventionTips":["Always keep at least one functional theme enabled on every tenant","Check startup logs for earlier shape/DI errors that cascade into layout failure","After theme changes, smoke-test a page render in staging","Run tenant requests inside a proper shell scope in custom middleware"],"tags":["layout","shapes","theming","rendering"],"backgroundTag":"resource-not-found","analyzedSha":"4306c0717fe573f6fca1b4955909ddab6a192807","analyzedAt":"2026-09-13T17:41:05.024Z","contentChangedAt":"2026-09-13T17:41:05.024Z","schemaVersion":2},"datasetVersion":"2026-09-15T23:17:13.987Z"}