{"record":{"id":"ba58399d62a46535","repo":"dotnet/maui","slug":"active-shell-item-not-set-have-you-added-any-shel-ba5839","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/iOS/ShellRenderer.cs","lineNumber":367,"sourceCode":"\t\t\t\tUpdateBackgroundColor();\n\t\t\t\tUpdateFlowDirection();\n\t\t\t}\n\t\t}\n\n\t\tprotected virtual void UpdateBackgroundColor()\n\t\t{\n\t\t\tvar color = Shell.BackgroundColor?.ToPlatform();\n\t\t\tif (color == null)\n\t\t\t\tcolor = Microsoft.Maui.Platform.ColorExtensions.BackgroundColor;\n\n\t\t\tFlyoutRenderer.View.BackgroundColor = color;\n\t\t}\n\n\t\tvoid SetupCurrentShellItem()\n\t\t{\n\t\t\tif (Shell.CurrentItem == null)\n\t\t\t{\n\t\t\t\tthrow new InvalidOperationException(\"Active Shell Item not set. Have you added any Shell Items to your Shell?\");\n\t\t\t}\n\t\t\telse if (Shell.CurrentItem.CurrentItem == null)\n\t\t\t{\n\t\t\t\tthrow new InvalidOperationException($\"Content not found for active {Shell.CurrentItem}. Title: {Shell.CurrentItem.Title}. Route: {Shell.CurrentItem.Route}.\");\n\t\t\t}\n\t\t\telse if (_currentShellItemRenderer == null)\n\t\t\t{\n\t\t\t\tOnCurrentItemChanged();\n\t\t\t}\n\t\t}\n\n\t\tbool IViewHandler.HasContainer { get => false; set { } }\n\n\t\tobject IViewHandler.ContainerView => null;\n\n\t\tIView IViewHandler.VirtualView => Element;\n\n\t\tobject IElementHandler.PlatformView => NativeView;","sourceCodeStart":349,"sourceCodeEnd":385,"githubUrl":"https://github.com/dotnet/maui/blob/f377ff1c5ee04d334d8a925f50c83a6b7afddf03/src/Controls/src/Core/Compatibility/Handlers/Shell/iOS/ShellRenderer.cs#L349-L385","documentation":"Thrown by the iOS ShellRenderer.SetupCurrentShellItem when Shell.CurrentItem is null. The Shell is the root visual element; its CurrentItem must be a valid ShellItem (flyout item, tab, or bottom-nav item). If no ShellItem has been added or CurrentItem is null, the renderer cannot set up the flyout content.","triggerScenarios":"At line 367: `if (Shell.CurrentItem == null) throw`. SetupCurrentShellItem is called during Shell initialization on iOS. Triggered when: (1) Shell has zero ShellItem children; (2) Shell.CurrentItem was explicitly set to null; (3) ShellItem auto-selection failed; (4) items were added after rendering started.","commonSituations":"1) App with `<Shell>` but no `<ShellItem>`/`<Tab>`/`<FlyoutItem>` children. 2) Shell items added dynamically after the Shell is already displayed. 3) ShellContent/ShellItem DataTemplates that failed to resolve, leaving the items collection effectively empty. 4) Routing configuration that prevents item auto-selection.","solutions":["Ensure at least one ShellItem (or FlyoutItem/Tab) exists in the Shell before it is rendered.","Add items in the Shell constructor or OnInitialized override, before the page is displayed.","Set Shell.CurrentItem explicitly after adding items programmatically.","Verify XAML Shell structure has valid ShellItem children with ShellContent.","Check that Routing.RegisterRoute calls and DataTemplates resolve correctly."],"exampleFix":"// before\npublic partial class AppShell : Shell\n{\n    public AppShell()\n    {\n        InitializeComponent();\n        // items added later — too late for iOS renderer init\n    }\n}\n\n// after\npublic partial class AppShell : Shell\n{\n    public AppShell()\n    {\n        InitializeComponent();\n        Items.Add(new FlyoutItem\n        {\n            Title = \"Home\",\n            Items = { new ShellContent { ContentTemplate = new DataTemplate(() => new HomePage()) } }\n        });\n        CurrentItem = Items[0];\n    }\n}","handlingStrategy":"validation","validationCode":"// Verify Shell has a current item before rendering\nif (Shell.CurrentItem == null)\n    throw new InvalidOperationException(\"Shell has no active ShellItem.\");","typeGuard":"public static bool ShellHasCurrentItem(Shell shell)\n    => shell?.CurrentItem != null;","tryCatchPattern":null,"preventionTips":["Add ShellItem children in the Shell constructor before it renders.","Set Shell.CurrentItem explicitly after adding items programmatically.","Write a startup validation that Shell.CurrentItem is non-null."],"tags":["maui","ios","shell","renderer"],"backgroundTag":null,"analyzedSha":"f377ff1c5ee04d334d8a925f50c83a6b7afddf03","analyzedAt":"2026-08-13T14:26:18.069Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}