{"record":{"id":"afaaf5e6ed3015ea","repo":"dotnet/maui","slug":"detail-cannot-be-set-to-null-once-a-value-is-set","errorCode":null,"errorMessage":"Detail cannot be set to null once a value is set.","messagePattern":"Detail cannot be set to null once a value is set\\.","errorType":"exception","errorClass":"ArgumentNullException","httpStatus":null,"severity":"error","filePath":"src/Controls/src/Core/FlyoutPage/FlyoutPage.cs","lineNumber":47,"sourceCode":"\n\t\tPage _detail;\n\n\t\tRect _detailBounds;\n\n\t\tPage _flyout;\n\n\t\tRect _flyoutBounds;\n\n\t\tIFlyoutPageController FlyoutPageController => this;\n\n\t\t/// <summary>Gets or sets the detail page that is used to display details about items on the flyout page.</summary>\n\t\tpublic Page Detail\n\t\t{\n\t\t\tget { return _detail; }\n\t\t\tset\n\t\t\t{\n\t\t\t\tif (_detail != null && value == null)\n\t\t\t\t\tthrow new ArgumentNullException(nameof(value), \"Detail cannot be set to null once a value is set.\");\n\n\t\t\t\tif (_detail == value)\n\t\t\t\t\treturn;\n\n\t\t\t\tif (value.RealParent != null)\n\t\t\t\t\tthrow new InvalidOperationException(\"Detail must not already have a parent.\");\n\n\t\t\t\tvar previousDetail = _detail;\n\n\t\t\t\tpreviousDetail?.SendNavigatingFrom(new NavigatingFromEventArgs(destinationPage: value, navigationType: NavigationType.Replace));\n\n\t\t\t\t// Update the detail property\n\t\t\t\tOnPropertyChanging();\n\t\t\t\tif (_detail is not null)\n\t\t\t\t\tInternalChildren.Remove(_detail);\n\t\t\t\t_detail = value;\n\t\t\t\tInternalChildren.Add(_detail);\n\t\t\t\tOnPropertyChanged();","sourceCodeStart":29,"sourceCodeEnd":65,"githubUrl":"https://github.com/dotnet/maui/blob/f377ff1c5ee04d334d8a925f50c83a6b7afddf03/src/Controls/src/Core/FlyoutPage/FlyoutPage.cs#L29-L65","documentation":"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.","triggerScenarios":"Assigning `flyoutPage.Detail = null;` after a non-null Detail was previously set. Common in navigation reset logic or when tearing down a screen.","commonSituations":"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.","solutions":["Replace the Detail with a new empty/placeholder Page instead of null: `flyoutPage.Detail = new ContentPage();`.","If you need to clear the whole FlyoutPage, remove the FlyoutPage from navigation rather than nulling Detail.","Bind Detail to a non-nullable Page property that always yields a valid page.","Guard any cleanup code against assigning null once Detail is set."],"exampleFix":"// before\nflyoutPage.Detail = null;\n\n// after\nflyoutPage.Detail = new ContentPage { Title = \"Empty\" };","handlingStrategy":"validation","validationCode":"if (flyoutPage.Detail != null && newDetail is null) flyoutPage.Detail = new ContentPage(); else flyoutPage.Detail = newDetail;","typeGuard":null,"tryCatchPattern":"try { flyoutPage.Detail = value; } catch (ArgumentNullException) { flyoutPage.Detail = new ContentPage(); }","preventionTips":["Never null out Detail after it is set; substitute an empty ContentPage.","Bind Detail to a non-nullable Page view-model property.","Clear the FlyoutPage from navigation rather than nulling its children."],"tags":["maui","flyoutpage","navigation","state"],"backgroundTag":null,"analyzedSha":"f377ff1c5ee04d334d8a925f50c83a6b7afddf03","analyzedAt":"2026-08-13T14:26:18.069Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}