dotnet/maui · error · InvalidOperationException

Flyout must be set before using a FlyoutPage

Error message

Flyout must be set before using a FlyoutPage

What it means

The IFlyoutPageController.FlyoutBounds setter throws InvalidOperationException when the renderer reports flyout layout bounds but Flyout was never assigned. Symmetric with DetailBounds: platform renderers push the measured flyout rect during layout, and a null Flyout means setup is incomplete.

Source

Thrown at src/Controls/src/Core/FlyoutPage/FlyoutPage.cs:177

		Rect IFlyoutPageController.DetailBounds
		{
			get { return _detailBounds; }
			set
			{
				_detailBounds = value;
				if (_detail == null)
					throw new InvalidOperationException("Detail must be set before using a FlyoutPage");
			}
		}

		Rect IFlyoutPageController.FlyoutBounds
		{
			get { return _flyoutBounds; }
			set
			{
				_flyoutBounds = value;
				if (_flyout == null)
					throw new InvalidOperationException("Flyout must be set before using a FlyoutPage");
			}
		}

		bool IFlyoutPageController.ShouldShowSplitMode
		{
			get
			{
				if (DeviceInfo.Idiom == DeviceIdiom.Phone)
					return false;

				FlyoutLayoutBehavior behavior = FlyoutLayoutBehavior;
				var orientation = Window.GetOrientation();

				bool isSplitOnLandscape = (behavior == FlyoutLayoutBehavior.SplitOnLandscape || behavior == FlyoutLayoutBehavior.Default) && orientation.IsLandscape();
				bool isSplitOnPortrait = behavior == FlyoutLayoutBehavior.SplitOnPortrait && orientation.IsPortrait();
				return behavior == FlyoutLayoutBehavior.Split || isSplitOnLandscape || isSplitOnPortrait;
			}
		}

View on GitHub (pinned to f377ff1c5e)

Solutions

  1. Set Flyout (with a non-empty Title) and Detail before the page enters the visual tree.
  2. In custom renderers, defer FlyoutBounds assignment until Flyout is non-null.
  3. Use a factory/builder that validates both children are present.

Example fix

// before
MainPage = new FlyoutPage { Detail = detail };
// renderer sets FlyoutBounds -> throws

// after
MainPage = new FlyoutPage { Flyout = new ContentPage{Title="Menu"}, Detail = detail };
Defensive patterns

Strategy: validation

Validate before calling

if (flyoutPage.Flyout is null) throw new InvalidOperationException("Set Flyout before layout");

Type guard

static bool IsFlyoutPageReady(FlyoutPage p) => p.Flyout is not null && p.Detail is not null;

Prevention

When it happens

Trigger: A FlyoutPage is laid out by the platform before its Flyout property is set, or a custom renderer assigns FlyoutBounds while Flyout is null.

Common situations: Setting Detail but forgetting Flyout, or a renderer that measures the master pane before the flyout page exists.

Related errors


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