dotnet/maui · error · InvalidOperationException
Active Shell Item not set. Have you added any Shell Items to
Error message
Active Shell Item not set. Have you added any Shell Items to your Shell?
What it means
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.
Source
Thrown at src/Controls/src/Core/Compatibility/Handlers/Shell/Android/ShellItemRenderer.cs:82
IMenuItem _updateMenuItemTitle;
IMenuItem _updateMenuItemIcon;
ShellSection _updateMenuItemSource;
public ShellItemRenderer(IShellContext shellContext) : base(shellContext)
{
}
public override AView OnCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
{
base.OnCreateView(inflater, container, savedInstanceState);
var context = MauiContext.Context;
_outerLayout = PlatformInterop.CreateNavigationBarOuterLayout(context);
_navigationArea = PlatformInterop.CreateNavigationBarArea(context, _outerLayout);
_bottomView = PlatformInterop.CreateNavigationBar(context, Resource.Attribute.bottomNavigationViewStyle, _outerLayout, this);
if (ShellItem is null)
throw new InvalidOperationException("Active Shell Item not set. Have you added any Shell Items to your Shell?");
if (ShellItem.CurrentItem is null)
throw new InvalidOperationException($"Content not found for active {ShellItem}. Title: {ShellItem.Title}. Route: {ShellItem.Route}.");
HookEvents(ShellItem);
SetupMenu();
_appearanceTracker = ShellContext.CreateBottomNavViewAppearanceTracker(ShellItem);
_bottomNavigationTracker = new BottomNavigationViewTracker();
((IShellController)ShellContext.Shell).AddAppearanceObserver(this, ShellItem);
return _outerLayout;
}
void Destroy()
{
if (ShellItem is not null)View on GitHub (pinned to f377ff1c5e)
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.
Example fix
// before
var shell = new Shell();
MainPage = shell; // no items yet — OnCreateView throws
shell.Items.Add(new ShellItem { ... });
// after
var shell = new Shell();
shell.Items.Add(new ShellItem { Items = { new ShellContent { ContentTemplate = ... } } });
shell.CurrentItem = shell.Items[0];
MainPage = shell; Defensive patterns
Strategy: validation
Validate before calling
// Verify Shell has items before it renders
if (Shell.CurrentItem == null || Shell.Items.Count == 0)
throw new InvalidOperationException("Shell must have at least one ShellItem."); Type guard
public static bool ShellHasItems(Shell shell)
=> shell != null && shell.Items.Count > 0 && shell.CurrentItem != null; Prevention
- 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.
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- Content not found for active {ShellItem}. Title: {ShellItem.
- Content not found for active {shellSection}. Title: {shellSe
- Unexpected navigation type
- LoadView must be called before accessing View
- Shell Content Page is Null
AI-assisted analysis of dotnet/maui@f377ff1c5e (2026-08-13).
Data as JSON: /api/errors/3b7b318d9c6efcc6.
Report an issue: GitHub.