dotnet/maui · error · InvalidOperationException

Content not found for active {shellSection}. Title: {shellSe

Error message

Content not found for active {shellSection}. Title: {shellSection.Title}. Route: {shellSection.Route}.

What it means

Thrown by the Android ShellSectionRenderer.OnCreateView when ShellSection.CurrentItem is null. A ShellSection (which represents a tab or section within a ShellItem) must have a currently selected ShellContent to display. If CurrentItem is null, the renderer cannot create the page view. The message includes Title and Route for diagnosis.

Source

Thrown at src/Controls/src/Core/Compatibility/Handlers/Shell/Android/ShellSectionRenderer.cs:102

		protected IShellContext ShellContext => _shellContext;
		IShellSectionController SectionController => (IShellSectionController)ShellSection;
		IMauiContext MauiContext => ShellContext.Shell.Handler.MauiContext;
		Toolbar _shellToolbar;

		public ShellSectionRenderer(IShellContext shellContext)
		{
			_shellContext = shellContext;
		}


		public override AView OnCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
		{
			var shellSection = ShellSection;
			if (shellSection == null)
				return null;

			if (shellSection.CurrentItem == null)
				throw new InvalidOperationException($"Content not found for active {shellSection}. Title: {shellSection.Title}. Route: {shellSection.Route}.");

			var context = Context;
			var root = PlatformInterop.CreateShellCoordinatorLayout(context);
			var appbar = PlatformInterop.CreateShellAppBar(context, Resource.Attribute.appBarLayoutStyle, root);

			MauiWindowInsetListener.SetupViewWithLocalListener(root);

			int actionBarHeight = context.GetActionBarHeight();

			_shellToolbar = new Toolbar(shellSection);
			ShellToolbarTracker.ApplyToolbarChanges(_shellContext.Shell.Toolbar, _shellToolbar);
			_toolbar = (AToolbar)_shellToolbar.ToPlatform(_shellContext.Shell.FindMauiContext());
			appbar.AddView(_toolbar);
			_tablayout = PlatformInterop.CreateShellTabLayout(context, appbar, actionBarHeight);

			var pagerContext = MauiContext.MakeScoped(layoutInflater: inflater, fragmentManager: ChildFragmentManager);
			var adapter = new ShellFragmentStateAdapter(shellSection, ChildFragmentManager, pagerContext);
			var pageChangedCallback = new ViewPagerPageChanged(this);

View on GitHub (pinned to f377ff1c5e)

Solutions

  1. Ensure every ShellSection has at least one ShellContent child with a valid Content or ContentTemplate.
  2. When creating ShellSections dynamically, add ShellContent and set CurrentItem before navigation triggers rendering.
  3. Verify the XAML hierarchy: Shell > ShellItem > ShellSection > ShellContent (each level must be populated).
  4. Check that route navigation targets a ShellContent, not an empty ShellSection.
  5. Use the Title/Route from the error message to locate the specific misconfigured ShellSection.

Example fix

// before
var section = new ShellSection { Title = "Tab1" };
// no ShellContent added
item.Items.Add(section);

// after
var section = new ShellSection { Title = "Tab1" };
section.Items.Add(new ShellContent
{
    ContentTemplate = new DataTemplate(() => new TabPage1()),
    Route = "tab1"
});
item.Items.Add(section);
Defensive patterns

Strategy: validation

Validate before calling

// Verify ShellSection has content before navigation
foreach (var section in shellItem.Items.OfType<ShellSection>())
{
    if (section.CurrentItem == null)
        throw new InvalidOperationException($"ShellSection '{section.Title}' has no ShellContent.");
}

Type guard

public static bool ShellSectionHasContent(ShellSection section)
    => section?.CurrentItem != null && section.Items.Count > 0;

Prevention

When it happens

Trigger: At line 102: `if (shellSection.CurrentItem == null) throw`. Occurs during the Android Fragment's OnCreateView lifecycle when the ShellSection bound to this renderer fragment has no active ShellContent. This happens when: (1) ShellSection was created without ShellContent children; (2) CurrentItem was set to null; (3) ShellContent was removed dynamically; (4) routing failed to select a ShellContent.

Common situations: 1) ShellSection defined in XAML with no ShellContent children. 2) Dynamic removal of the only ShellContent from a ShellSection while the fragment is active. 3) ShellSection created in code without adding ShellContent. 4) Route-based navigation that lands on an empty ShellSection. 5) Tab/Flyout structure where a ShellSection is referenced but its content was never defined.

Related errors


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