dotnet/maui · error · ArgumentNullException

Flyout cannot be set to null once a value is set

Error message

Flyout cannot be set to null once a value is set

What it means

FlyoutPage.Flyout setter throws ArgumentNullException when an existing Flyout is being replaced by null. The flyout pane is structurally required by every FlyoutPage layout; clearing it would leave the split/drawer layout with no menu surface, so the API forbids null after a value is set.

Source

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

			get { return (bool)GetValue(IsGestureEnabledProperty); }
			set { SetValue(IsGestureEnabledProperty, BooleanBoxes.Box(value)); }
		}

		/// <summary>Gets or sets a value that indicates whether the flyout is presented. This is a bindable property.</summary>
		public bool IsPresented
		{
			get { return (bool)GetValue(IsPresentedProperty); }
			set { SetValue(IsPresentedProperty, BooleanBoxes.Box(value)); }
		}

		/// <summary>Gets or sets the flyout page that is used to present a menu or navigation options.</summary>
		public Page Flyout
		{
			get { return _flyout; }
			set
			{
				if (_flyout != null && value == null)
					throw new ArgumentNullException(nameof(value), "Flyout cannot be set to null once a value is set");

				if (string.IsNullOrEmpty(value.Title))
					throw new InvalidOperationException("Title property must be set on Flyout page");

				if (_flyout == value)
					return;

				if (value.RealParent != null)
					throw new InvalidOperationException("Flyout must not already have a parent.");

				// TODO MAUI refine this to fire earlier
				var previousFlyout = _flyout;
				
				// TODO MAUI refine this to fire earlier
				previousFlyout?.SendNavigatingFrom(new NavigatingFromEventArgs(value, NavigationType.Replace));

				OnPropertyChanging();
				if (_flyout != null)

View on GitHub (pinned to f377ff1c5e)

Solutions

  1. Replace the Flyout with a minimal placeholder Page (with a Title) instead of null.
  2. Hide the flyout via IsPresented=false or FlyoutLayoutBehavior rather than nulling the page.
  3. Bind Flyout to a non-nullable Page that always returns a valid (even if empty) menu page.

Example fix

// before
flyoutPage.Flyout = null;

// after
flyoutPage.Flyout = new ContentPage { Title = "Menu" };
flyoutPage.IsPresented = false;
Defensive patterns

Strategy: validation

Validate before calling

if (flyoutPage.Flyout != null && newFlyout is null) flyoutPage.Flyout = new ContentPage{Title="Menu"}; else flyoutPage.Flyout = newFlyout;

Try / catch

try { flyoutPage.Flyout = value; } catch (ArgumentNullException) { flyoutPage.Flyout = new ContentPage{Title="Menu"}; }

Prevention

When it happens

Trigger: Assigning `flyoutPage.Flyout = null;` after a non-null Flyout was previously set, e.g. in a teardown or conditional-menu path.

Common situations: Logout flows, conditional menus that hide the flyout by nulling it, or view-model bindings that expose a nullable flyout page.

Related errors


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