{"record":{"id":"9930b90e580f3631","repo":"dotnet/maui","slug":"shell-content-page-is-null","errorCode":null,"errorMessage":"Shell Content Page is Null","messagePattern":"Shell Content Page is Null","errorType":"exception","errorClass":"ArgumentNullException","httpStatus":null,"severity":"error","filePath":"src/Controls/src/Core/Compatibility/Handlers/Shell/Android/ShellSectionRenderer.cs","lineNumber":42,"sourceCode":"{\n\tpublic class ShellSectionRenderer : Fragment, IShellSectionRenderer//, ViewPager.IOnPageChangeListener\n\t\t, AView.IOnClickListener, IShellObservableFragment, IAppearanceObserver, TabLayoutMediator.ITabConfigurationStrategy\n\t{\n\t\t#region ITabConfigurationStrategy\n\n\t\tvoid TabLayoutMediator.ITabConfigurationStrategy.OnConfigureTab(TabLayout.Tab tab, int position)\n\t\t{\n\t\t\ttab.SetText(new String(SectionController.GetItems()[position].Title));\n\t\t}\n\n\t\tvoid UpdateCurrentItem(ShellContent content)\n\t\t{\n\t\t\tif (_toolbarTracker == null)\n\t\t\t\treturn;\n\n\t\t\tvar page = ((IShellContentController)content).GetOrCreateContent();\n\t\t\tif (page == null)\n\t\t\t\tthrow new ArgumentNullException(nameof(page), \"Shell Content Page is Null\");\n\n\t\t\tShellSection.SetValueFromRenderer(ShellSection.CurrentItemProperty, content);\n\t\t\t_toolbarTracker.Page = page;\n\t\t}\n\n\t\t#endregion IOnPageChangeListener\n\n\t\t#region IAppearanceObserver\n\n\t\tvoid IAppearanceObserver.OnAppearanceChanged(ShellAppearance appearance)\n\t\t{\n\t\t\tif (appearance == null)\n\t\t\t\tResetAppearance();\n\t\t\telse\n\t\t\t\tSetAppearance(appearance);\n\t\t}\n\n\t\t#endregion IAppearanceObserver","sourceCodeStart":24,"sourceCodeEnd":60,"githubUrl":"https://github.com/dotnet/maui/blob/f377ff1c5ee04d334d8a925f50c83a6b7afddf03/src/Controls/src/Core/Compatibility/Handlers/Shell/Android/ShellSectionRenderer.cs#L24-L60","documentation":"Thrown by the Android ShellSectionRenderer in UpdateCurrentItem when GetOrCreateContent() returns null for a ShellContent. The cast `(IShellContentController)content).GetOrCreateContent()` should always produce a Page (lazily creating it from the ContentTemplate), so a null result indicates the ContentTemplate failed to instantiate a page, or the ShellContent was misconfigured. The exception is ArgumentNullException with the parameter name 'page'.","triggerScenarios":"At line 42: `var page = ((IShellContentController)content).GetOrCreateContent(); if (page == null) throw new ArgumentNullException`. Triggered when: (1) ShellContent.ContentTemplate is null or its DataTemplate factory returns null; (2) the ShellContent's Content property was explicitly set to null; (3) a DataTemplate referencing a type that failed to construct threw silently and returned null; (4) the ShellContent was created programmatically without setting Content or ContentTemplate.","commonSituations":"1) ShellContent defined with `ContentTemplate=\"{x:DataTemplate ...}\"` where the DataTemplate's root type threw during construction. 2) ShellContent created in code without Content or ContentTemplate. 3) DI/constructor injection failure in the page type referenced by the DataTemplate (constructor throws, factory returns null). 4) XAML DataTemplate referencing a type that was removed or renamed.","solutions":["Verify the ShellContent has a valid ContentTemplate with a DataTemplate that reliably constructs a non-null Page.","If the page type has constructor dependencies (DI), ensure they are registered in MauiProgram and the page is resolvable.","Add error handling/logging inside the DataTemplate factory to catch construction failures.","Test the page type instantiation independently to confirm it constructs without throwing.","Set ShellContent.Content directly to a page instance if ContentTemplate is problematic."],"exampleFix":"// before\nnew ShellContent\n{\n    Route = \"home\",\n    ContentTemplate = new DataTemplate(() => null) // factory returns null\n}\n\n// after\nnew ShellContent\n{\n    Route = \"home\",\n    ContentTemplate = new DataTemplate(() => new HomePage(service))\n}\n// or set Content directly:\nnew ShellContent { Content = new HomePage() }","handlingStrategy":"validation","validationCode":"// Verify content can be created before assigning\nvar testContent = ((IShellContentController)shellContent)?.GetOrCreateContent();\nif (testContent == null)\n    throw new InvalidOperationException(\"ShellContent failed to create a page.\");","typeGuard":"public static bool ShellContentResolves(ShellContent content)\n{\n    try { return ((IShellContentController)content)?.GetOrCreateContent() != null; }\n    catch { return false; }\n}","tryCatchPattern":null,"preventionTips":["Test DataTemplate factory methods independently to ensure they return non-null pages.","Register all DI dependencies for page types in MauiProgram.","Set ShellContent.Content directly if ContentTemplate is unreliable."],"tags":["maui","android","shell","datatemplate","di","renderer"],"backgroundTag":null,"analyzedSha":"f377ff1c5ee04d334d8a925f50c83a6b7afddf03","analyzedAt":"2026-08-13T14:26:18.069Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}