dotnet/maui · error · InvalidOperationException

Content not found for active {Shell.CurrentItem}. Title: {Sh

Error message

Content not found for active {Shell.CurrentItem}. Title: {Shell.CurrentItem.Title}. Route: {Shell.CurrentItem.Route}.

What it means

Thrown by the iOS ShellRenderer.SetupCurrentShellItem when Shell.CurrentItem exists but Shell.CurrentItem.CurrentItem is null. Shell.CurrentItem is a ShellItem, and ShellItem.CurrentItem is the active ShellContent within that item. If the ShellItem has no selected ShellContent, the renderer cannot proceed. This is the second check in the SetupCurrentShellItem cascade (after the null-ShellItem check).

Source

Thrown at src/Controls/src/Core/Compatibility/Handlers/Shell/iOS/ShellRenderer.cs:371

		protected virtual void UpdateBackgroundColor()
		{
			var color = Shell.BackgroundColor?.ToPlatform();
			if (color == null)
				color = Microsoft.Maui.Platform.ColorExtensions.BackgroundColor;

			FlyoutRenderer.View.BackgroundColor = color;
		}

		void SetupCurrentShellItem()
		{
			if (Shell.CurrentItem == null)
			{
				throw new InvalidOperationException("Active Shell Item not set. Have you added any Shell Items to your Shell?");
			}
			else if (Shell.CurrentItem.CurrentItem == null)
			{
				throw new InvalidOperationException($"Content not found for active {Shell.CurrentItem}. Title: {Shell.CurrentItem.Title}. Route: {Shell.CurrentItem.Route}.");
			}
			else if (_currentShellItemRenderer == null)
			{
				OnCurrentItemChanged();
			}
		}

		bool IViewHandler.HasContainer { get => false; set { } }

		object IViewHandler.ContainerView => null;

		IView IViewHandler.VirtualView => Element;

		object IElementHandler.PlatformView => NativeView;

		Maui.IElement IElementHandler.VirtualView => Element;

		IMauiContext IElementHandler.MauiContext => _mauiContext;

View on GitHub (pinned to f377ff1c5e)

Solutions

  1. Ensure the active ShellItem has at least one ShellContent child with a valid Content or ContentTemplate.
  2. Set ShellItem.CurrentItem explicitly to a ShellContent when building items in code.
  3. Verify the XAML hierarchy: Shell > ShellItem > ShellContent is fully populated.
  4. Inspect the Title and Route from the error message to identify the specific ShellItem missing content.
  5. Test ShellContent DataTemplate resolution independently.

Example fix

<!-- before -->
<ShellItem Title="Settings">
  <!-- no ShellContent here -->
</ShellItem>

<!-- after -->
<ShellItem Title="Settings">
  <ShellContent Title="Settings" ContentTemplate="{DataTemplate local:SettingsPage}" Route="settings"/>
</ShellItem>
Defensive patterns

Strategy: validation

Validate before calling

// Verify ShellItem has content on iOS
if (Shell.CurrentItem?.CurrentItem == null)
    throw new InvalidOperationException("Active ShellItem has no ShellContent.");

Type guard

public static bool ShellItemHasActiveContent(ShellItem item)
    => item?.CurrentItem != null;

Prevention

When it happens

Trigger: At line 371: `else if (Shell.CurrentItem.CurrentItem == null) throw`. Triggered when Shell.CurrentItem is a valid ShellItem but that item has no ShellContent selected (CurrentItem is null). This happens when: (1) the active ShellItem has no ShellContent children; (2) ShellContent was removed; (3) CurrentItem auto-selection within the ShellItem failed.

Common situations: 1) ShellItem defined in XAML without any ShellContent children. 2) ShellItem whose ShellContent DataTemplate failed to instantiate. 3) Dynamic removal of the only ShellContent from the active ShellItem. 4) Shell structure where ShellItem contains only nested ShellItems (unusual/invalid structure). 5) Migration issues where ShellContent auto-generation differs from Xamarin.Forms.

Related errors


AI-assisted analysis of dotnet/maui@f377ff1c5e (2026-08-13). Data as JSON: /api/errors/065df27dce018270. Report an issue: GitHub.