dotnet/maui · error · InvalidOperationException

Flyout must not already have a parent.

Error message

Flyout must not already have a parent.

What it means

FlyoutPage.Flyout setter throws InvalidOperationException when the incoming Page already has a RealParent. A Maui Element may belong to only one parent; assigning an already-parented page as Flyout would detach it inconsistently from its current container.

Source

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

		}

		/// <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)
					InternalChildren.Remove(_flyout);
				_flyout = value;
				InternalChildren.Add(_flyout);
				OnPropertyChanged();

				if (this.HasAppeared)
				{
					previousFlyout?.SendDisappearing();
					_flyout?.SendAppearing();

View on GitHub (pinned to f377ff1c5e)

Solutions

  1. Instantiate a new Page for the Flyout assignment.
  2. Detach the page from its current parent (reassign the old container's property) before reusing.
  3. Never reuse a single Page instance as both Flyout and Detail.
  4. Validate `value.RealParent == null` before assigning.

Example fix

// before
flyoutPage.Flyout = flyoutPage.Detail; // Detail already parented

// after
flyoutPage.Flyout = new FlyoutMenuPage();
Defensive patterns

Strategy: validation

Validate before calling

if (value.RealParent != null) throw new InvalidOperationException("Page already parented"); flyoutPage.Flyout = value;

Type guard

static bool IsUnparented(Page p) => p.RealParent is null;

Try / catch

try { flyoutPage.Flyout = value; } catch (InvalidOperationException) { flyoutPage.Flyout = value.Clone() /* or new instance */; }

Prevention

When it happens

Trigger: Assigning a Page to Flyout that is currently the Detail, a child of another FlyoutPage, the root of a NavigationPage, or a child of any Layout.

Common situations: Swapping Flyout and Detail using the same instance, sharing a menu page across multiple FlyoutPages, or reusing a page from a navigation stack.

Related errors


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