dotnet/maui · error · ArgumentNullException

Detail cannot be set to null once a value is set.

Error message

Detail cannot be set to null once a value is set.

What it means

FlyoutPage.Detail setter throws ArgumentNullException when an existing Detail is being replaced by null. Once a Detail is assigned, the page's layout, handlers, and child collection assume a non-null detail; clearing it would leave the layout in an inconsistent state, so the API forbids it.

Source

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

		Page _detail;

		Rect _detailBounds;

		Page _flyout;

		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();

View on GitHub (pinned to f377ff1c5e)

Solutions

  1. Replace the Detail with a new empty/placeholder Page instead of null: `flyoutPage.Detail = new ContentPage();`.
  2. If you need to clear the whole FlyoutPage, remove the FlyoutPage from navigation rather than nulling Detail.
  3. Bind Detail to a non-nullable Page property that always yields a valid page.
  4. Guard any cleanup code against assigning null once Detail is set.

Example fix

// before
flyoutPage.Detail = null;

// after
flyoutPage.Detail = new ContentPage { Title = "Empty" };
Defensive patterns

Strategy: validation

Validate before calling

if (flyoutPage.Detail != null && newDetail is null) flyoutPage.Detail = new ContentPage(); else flyoutPage.Detail = newDetail;

Try / catch

try { flyoutPage.Detail = value; } catch (ArgumentNullException) { flyoutPage.Detail = new ContentPage(); }

Prevention

When it happens

Trigger: Assigning `flyoutPage.Detail = null;` after a non-null Detail was previously set. Common in navigation reset logic or when tearing down a screen.

Common situations: Logout/cleanup flows that null out child pages, reactive view models that bind Detail to a nullable property, or replacing a detail by first nulling then re-assigning.

Related errors


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