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 iOS ShellSectionRootRenderer.ViewDidLoad when ShellSection.CurrentItem is null. The ShellSectionRootRenderer is the UIViewController for a ShellSection's root content on iOS. ViewDidLoad is called once when the view controller's view is first loaded; if the ShellSection has no active ShellContent at that point, the renderer cannot build its content area.

Source

Thrown at src/Controls/src/Core/Compatibility/Handlers/Shell/iOS/ShellSectionRootRenderer.cs:111

		{
			base.TraitCollectionDidChange(previousTraitCollection);
			if (previousTraitCollection?.VerticalSizeClass != TraitCollection.VerticalSizeClass ||
				previousTraitCollection?.HorizontalSizeClass != TraitCollection.HorizontalSizeClass)
			{
				if (OperatingSystem.IsIOSVersionAtLeast(26) || OperatingSystem.IsMacCatalystVersionAtLeast(26))
				{
					(_tracker as ShellPageRendererTracker)?.UpdateTitleViewFrameForOrientation();
				}
			}
		}

		public override void ViewDidLoad()
		{
			if (_isDisposed)
				return;

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

			base.ViewDidLoad();

			_containerArea = new UIView();
			if (OperatingSystem.IsIOSVersionAtLeast(11) || OperatingSystem.IsMacCatalystVersionAtLeast(11)
#if TVOS
				|| OperatingSystem.IsTvOSVersionAtLeast(11)
#endif
			)
			{
				_containerArea.InsetsLayoutMarginsFromSafeArea = false;
			}

			View.AddSubview(_containerArea);

			LoadRenderers();

			ShellSection.PropertyChanged += OnShellSectionPropertyChanged;

View on GitHub (pinned to f377ff1c5e)

Solutions

  1. Ensure every ShellSection has at least one ShellContent child before its view controller loads.
  2. When creating sections dynamically, add ShellContent and set CurrentItem before navigation.
  3. Verify XAML structure: ShellSection must contain ShellContent with valid Content/ContentTemplate.
  4. Use the Title/Route from the error to locate the specific ShellSection.
  5. Avoid removing the active ShellContent while the section is visible — switch CurrentItem first.

Example fix

// before
var section = new ShellSection { Title = "Browse", Route = "browse" };
item.Items.Add(section);
// no ShellContent — ViewDidLoad will throw

// after
var section = new ShellSection { Title = "Browse", Route = "browse" };
section.Items.Add(new ShellContent
{
    ContentTemplate = new DataTemplate(() => new BrowsePage()),
    Route = "browsecontent"
});
item.Items.Add(section);
Defensive patterns

Strategy: validation

Validate before calling

// Verify ShellSection has content before ViewDidLoad fires
if (shellSection.CurrentItem == null)
    throw new InvalidOperationException($"ShellSection '{shellSection.Title}' has no content.");

Type guard

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

Prevention

When it happens

Trigger: At line 111: `if (ShellSection.CurrentItem == null) throw`. ViewDidLoad is a UIKit lifecycle method. Triggered when: (1) the ShellSection has no ShellContent children; (2) CurrentItem was nulled or not set; (3) the view controller was loaded before content was assigned (timing issue); (4) ShellContent was removed during the section's lifecycle.

Common situations: 1) ShellSection defined without ShellContent children in XAML. 2) Dynamic removal of ShellContent while the section's view controller is loading. 3) Route-based navigation that lands on an empty ShellSection. 4) ShellSection created programmatically without adding content. 5) Lifecycle timing where ViewDidLoad fires before ShellSection is fully configured.

Related errors


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