{"record":{"id":"3b7b318d9c6efcc6","repo":"dotnet/maui","slug":"active-shell-item-not-set-have-you-added-any-shel","errorCode":null,"errorMessage":"Active Shell Item not set. Have you added any Shell Items to your Shell?","messagePattern":"Active Shell Item not set\\. Have you added any Shell Items to your Shell\\?","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"src/Controls/src/Core/Compatibility/Handlers/Shell/Android/ShellItemRenderer.cs","lineNumber":82,"sourceCode":"\t\tIMenuItem _updateMenuItemTitle;\n\t\tIMenuItem _updateMenuItemIcon;\n\t\tShellSection _updateMenuItemSource;\n\n\t\tpublic ShellItemRenderer(IShellContext shellContext) : base(shellContext)\n\t\t{\n\t\t}\n\n\t\tpublic override AView OnCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)\n\t\t{\n\t\t\tbase.OnCreateView(inflater, container, savedInstanceState);\n\n\t\t\tvar context = MauiContext.Context;\n\t\t\t_outerLayout = PlatformInterop.CreateNavigationBarOuterLayout(context);\n\t\t\t_navigationArea = PlatformInterop.CreateNavigationBarArea(context, _outerLayout);\n\t\t\t_bottomView = PlatformInterop.CreateNavigationBar(context, Resource.Attribute.bottomNavigationViewStyle, _outerLayout, this);\n\n\t\t\tif (ShellItem is null)\n\t\t\t\tthrow new InvalidOperationException(\"Active Shell Item not set. Have you added any Shell Items to your Shell?\");\n\n\t\t\tif (ShellItem.CurrentItem is null)\n\t\t\t\tthrow new InvalidOperationException($\"Content not found for active {ShellItem}. Title: {ShellItem.Title}. Route: {ShellItem.Route}.\");\n\n\t\t\tHookEvents(ShellItem);\n\t\t\tSetupMenu();\n\n\t\t\t_appearanceTracker = ShellContext.CreateBottomNavViewAppearanceTracker(ShellItem);\n\t\t\t_bottomNavigationTracker = new BottomNavigationViewTracker();\n\t\t\t((IShellController)ShellContext.Shell).AddAppearanceObserver(this, ShellItem);\n\n\t\t\treturn _outerLayout;\n\t\t}\n\n\n\t\tvoid Destroy()\n\t\t{\n\t\t\tif (ShellItem is not null)","sourceCodeStart":64,"sourceCodeEnd":100,"githubUrl":"https://github.com/dotnet/maui/blob/f377ff1c5ee04d334d8a925f50c83a6b7afddf03/src/Controls/src/Core/Compatibility/Handlers/Shell/Android/ShellItemRenderer.cs#L64-L100","documentation":"Thrown by the Android ShellItemRenderer.OnCreateView when the ShellItem property is null. The renderer is a Fragment that represents a ShellItem (bottom navigation tab). OnCreateView is called by the Android FragmentManager when the fragment's view needs to be created, and if the bound ShellItem was never set or was nulled out before this lifecycle call, the renderer cannot proceed. It suggests the Shell has no visible items or the data binding to ShellItem failed.","triggerScenarios":"Occurs in `OnCreateView` at line 82: `if (ShellItem is null) throw`. The ShellItem is typically set via the ShellContext before the fragment is displayed. This fires when: (1) the Shell has zero ShellItem children; (2) the Shell.CurrentItem was set to null or an item that doesn't exist; (3) the Shell's Items collection is empty at the time the fragment is created; (4) the ShellContext binding pipeline failed to assign ShellItem before the fragment lifecycle advanced.","commonSituations":"1) App defined with `<Shell>` but no `<ShellItem>` children (empty Shell). 2) Dynamically building Shell items but navigating/routing before items are added. 3) Shell defined with only a single ShellContent directly under Shell (not wrapped in ShellItem) and the auto-generation didn't fire. 4) Binding errors where ShellItemSource or routing failed to resolve. 5) Migration from Xamarin.Forms Shell where item registration timing differs.","solutions":["Ensure at least one ShellItem exists in the Shell before the app navigates: add `<ShellItem>` or `<Tab>` with `<ShellContent>` in XAML, or register items in code before MainPage/set.","Verify Shell.CurrentItem is set to a valid ShellItem and that GoToAsync routes resolve to existing items.","If building items dynamically, add them to Shell.Items before triggering navigation or before OnCreateView fires (e.g., in the Shell constructor or OnInitialized).","Check XAML for typos in route registration or DataTemplate mismatches that prevent ShellContent from being created.","Use Shell.CurrentItem = shellItem explicitly after adding items to ensure the active item is set."],"exampleFix":"// before\nvar shell = new Shell();\nMainPage = shell; // no items yet — OnCreateView throws\nshell.Items.Add(new ShellItem { ... });\n\n// after\nvar shell = new Shell();\nshell.Items.Add(new ShellItem { Items = { new ShellContent { ContentTemplate = ... } } });\nshell.CurrentItem = shell.Items[0];\nMainPage = shell;","handlingStrategy":"validation","validationCode":"// Verify Shell has items before it renders\nif (Shell.CurrentItem == null || Shell.Items.Count == 0)\n    throw new InvalidOperationException(\"Shell must have at least one ShellItem.\");","typeGuard":"public static bool ShellHasItems(Shell shell)\n    => shell != null && shell.Items.Count > 0 && shell.CurrentItem != null;","tryCatchPattern":null,"preventionTips":["Add ShellItem children in the Shell constructor or XAML before rendering.","Set Shell.CurrentItem explicitly when building items dynamically.","Write a startup check that Shell.Items is non-empty."],"tags":["maui","android","shell","renderer","fragment"],"backgroundTag":null,"analyzedSha":"f377ff1c5ee04d334d8a925f50c83a6b7afddf03","analyzedAt":"2026-08-13T14:26:18.069Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}