dotnet/maui · error · InvalidOperationException
Detail must not already have a parent.
Error message
Detail must not already have a parent.
What it means
FlyoutPage.Detail setter throws InvalidOperationException when the incoming Page already has a RealParent, because an Element can only belong to one visual tree. Re-parenting a page that is still a child of another FlyoutPage, NavigationPage, or layout would corrupt both trees.
Source
Thrown at src/Controls/src/Core/FlyoutPage/FlyoutPage.cs:53
Rect _flyoutBounds;
IFlyoutPageController FlyoutPageController => this;
/// <summary>Gets or sets the detail page that is used to display details about items on the flyout page.</summary>
public Page Detail
{
get { return _detail; }
set
{
if (_detail != null && value == null)
throw new ArgumentNullException(nameof(value), "Detail cannot be set to null once a value is set.");
if (_detail == value)
return;
if (value.RealParent != null)
throw new InvalidOperationException("Detail must not already have a parent.");
var previousDetail = _detail;
previousDetail?.SendNavigatingFrom(new NavigatingFromEventArgs(destinationPage: value, navigationType: NavigationType.Replace));
// Update the detail property
OnPropertyChanging();
if (_detail is not null)
InternalChildren.Remove(_detail);
_detail = value;
InternalChildren.Add(_detail);
OnPropertyChanged();
// Handle Appearing/Disappearing events if the FlyoutPage has appeared
if (HasAppeared)
{
previousDetail?.SendDisappearing();
_detail?.SendAppearing();View on GitHub (pinned to f377ff1c5e)
Solutions
- Create a fresh Page instance for the new Detail rather than reusing one already parented.
- Remove the page from its current parent before reassigning (set the old parent's corresponding property to a different page).
- Avoid caching and reusing Page instances across containers; recreate them per navigation.
- Check `value.RealParent == null` before assigning if reuse is intentional.
Example fix
// before flyoutPage2.Detail = flyoutPage1.Detail; // already parented // after flyoutPage2.Detail = new MyDetailPage(); // fresh instance
Defensive patterns
Strategy: validation
Validate before calling
if (value.RealParent != null) throw new InvalidOperationException("Page already parented"); flyoutPage.Detail = value; Type guard
static bool IsUnparented(Page p) => p.RealParent is null;
Try / catch
try { flyoutPage.Detail = value; } catch (InvalidOperationException) { flyoutPage.Detail = value.Clone() /* or new instance */; } Prevention
- Do not reuse a Page instance across containers.
- Detach a page from its current parent before reassigning.
- Check RealParent before assigning to Detail.
When it happens
Trigger: Assigning a Page instance to Detail that is already a child of another container (another FlyoutPage.Detail, NavigationPage root, or a Layout's Children) without removing it first.
Common situations: Sharing a single Page instance across multiple FlyoutPage instances, reusing a cached detail page that was never detached, or moving a page between navigation stacks.
Related errors
- Flyout must not already have a parent.
- Detail cannot be set to null once a value is set.
- Flyout cannot be set to null once a value is set
- Title property must be set on Flyout page
- PopToRootAsync is not supported globally on GTK, please use
AI-assisted analysis of dotnet/maui@f377ff1c5e (2026-08-13).
Data as JSON: /api/errors/e0b6f73af57c1496.
Report an issue: GitHub.