{"record":{"id":"d6348adfb50ba186","repo":"dotnet/maui","slug":"contentloader","errorCode":null,"errorMessage":"ContentLoader","messagePattern":"ContentLoader","errorType":"exception","errorClass":"ArgumentNullException","httpStatus":null,"severity":"error","filePath":"src/Compatibility/Core/src/WPF/Controls/FormWindow.cs","lineNumber":179,"sourceCode":"\t\t{\n\t\t\tif (CurrentFlyoutPage != null)\n\t\t\t{\n\t\t\t\tCurrentFlyoutPage.IsPresented = !CurrentFlyoutPage.IsPresented;\n\t\t\t}\n\t\t}\n\n\t\tprivate void PreviousButton_Click(object sender, RoutedEventArgs e)\n\t\t{\n\t\t\tif (CurrentNavigationPage != null && CurrentNavigationPage.StackDepth > 1)\n\t\t\t{\n\t\t\t\tCurrentNavigationPage.OnBackButtonPressed();\n\t\t\t}\n\t\t}\n\n\t\tprivate static void OnContentLoaderChanged(DependencyObject o, DependencyPropertyChangedEventArgs e)\n\t\t{\n\t\t\tif (e.NewValue == null)\n\t\t\t\tthrow new ArgumentNullException(\"ContentLoader\");\n\t\t}\n\n\t\tpublic void SynchronizeAppBar()\n\t\t{\n\t\t\tIEnumerable<FormsPage> childrens = this.FindVisualChildren<FormsPage>();\n\n\t\t\tCurrentTitle = childrens.FirstOrDefault()?.GetTitle();\n\t\t\tHasNavigationBar = childrens.FirstOrDefault()?.GetHasNavigationBar() ?? false;\n\t\t\tCurrentNavigationPage = childrens.OfType<FormsNavigationPage>()?.FirstOrDefault();\n\t\t\tCurrentFlyoutPage = childrens.OfType<FormsFlyoutPage>()?.FirstOrDefault();\n\t\t\tvar page = childrens.FirstOrDefault();\n\t\t\tif (page != null)\n\t\t\t{\n\t\t\t\tTitleBarBackgroundColor = page.GetTitleBarBackgroundColor();\n\t\t\t\tTitleBarTextColor = page.GetTitleBarTextColor();\n\t\t\t}\n\t\t\telse\n\t\t\t{","sourceCodeStart":161,"sourceCodeEnd":197,"githubUrl":"https://github.com/dotnet/maui/blob/f377ff1c5ee04d334d8a925f50c83a6b7afddf03/src/Compatibility/Core/src/WPF/Controls/FormWindow.cs#L161-L197","documentation":"FormWindow.OnContentLoaderChanged is a WPF DependencyProperty property-changed callback that throws ArgumentNullException(\"ContentLoader\") when the new value is null. The FormWindow requires a non-null IContentLoader to load page content; a null binding breaks window content resolution.","triggerScenarios":"Setting FormWindow.ContentLoader (via XAML or code) to null; a binding to ContentLoader that resolves to null because the source or DataContext is unset; a StaticResource/DynamicResource for the loader that fails to resolve.","commonSituations":"XAML assigns ContentLoader through a binding whose path returns null; resource key typo so {StaticResource} fails; cleanup code sets ContentLoader to null during teardown; swapping loaders without keeping a default instance.","solutions":["Always assign a non-null IContentLoader (e.g. new FormsContentLoader()) to FormWindow.ContentLoader.","If using a binding, ensure the source property never returns null, or use FallbackValue.","In cleanup, dispose the loader rather than nulling the property.","Validate resource keys for {StaticResource}/{DynamicResource} ContentLoader assignments."],"exampleFix":"// before\n<controls:FormWindow ContentLoader=\"{Binding Loader}\" />\n\n// after\n<controls:FormWindow ContentLoader=\"{Binding Loader, FallbackValue={x:Static local:FormsContentLoader.Default}}\" />","handlingStrategy":"validation","validationCode":"if (loader == null) throw new InvalidOperationException(\"ContentLoader must be set before use\");\nwindow.ContentLoader = loader ?? new FormsContentLoader();","typeGuard":"static bool HasValidLoader(FormWindow w) => w.ContentLoader != null;","tryCatchPattern":"try { window.ContentLoader = candidate; }\ncatch (ArgumentNullException) { window.ContentLoader = new FormsContentLoader(); }","preventionTips":["Always assign a concrete FormsContentLoader/DefaultContentLoader in XAML or code-behind.","Use FallbackValue on ContentLoader bindings to avoid null resolution.","Never null the property during teardown; dispose underlying content instead."],"tags":["wpf","dependency-property","argumentnull","content-loader","binding"],"backgroundTag":null,"analyzedSha":"f377ff1c5ee04d334d8a925f50c83a6b7afddf03","analyzedAt":"2026-08-13T14:26:18.069Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}