{"record":{"id":"89fe487131ad2c8e","repo":"dotnet/maui","slug":"contentloader-89fe48","errorCode":null,"errorMessage":"ContentLoader","messagePattern":"ContentLoader","errorType":"exception","errorClass":"ArgumentNullException","httpStatus":null,"severity":"error","filePath":"src/Compatibility/Core/src/WPF/Controls/FormsContentControl.cs","lineNumber":44,"sourceCode":"\t\t\tset { SetValue(ContentLoaderProperty, value); }\n\t\t}\n\n\t\tpublic FormsContentControl()\n\t\t{\n\t\t\tthis.DefaultStyleKey = typeof(FormsContentControl);\n\t\t\tthis.SizeChanged += LightContentControl_SizeChanged;\n\t\t}\n\n\t\tprivate void LightContentControl_SizeChanged(object sender, SizeChangedEventArgs e)\n\t\t{\n\t\t\tthis.ContentLoader.OnSizeContentChanged(this, Source);\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{\n\t\t\t\tthrow new ArgumentNullException(\"ContentLoader\");\n\t\t\t}\n\t\t}\n\n\t\tprivate static void OnSourceChanged(DependencyObject o, DependencyPropertyChangedEventArgs e)\n\t\t{\n\t\t\t((FormsContentControl)o).OnSourceChanged(e.OldValue, e.NewValue);\n\t\t}\n\n\t\tprivate void OnSourceChanged(object oldValue, object newValue)\n\t\t{\n\t\t\tif (newValue != null && newValue.Equals(oldValue))\n\t\t\t\treturn;\n\n\t\t\tvar localTokenSource = new CancellationTokenSource();\n\t\t\tthis.tokenSource = localTokenSource;\n\n\t\t\tvar scheduler = TaskScheduler.FromCurrentSynchronizationContext();\n\t\t\tvar task = this.ContentLoader.LoadContentAsync(this, oldValue, newValue, this.tokenSource.Token);","sourceCodeStart":26,"sourceCodeEnd":62,"githubUrl":"https://github.com/dotnet/maui/blob/f377ff1c5ee04d334d8a925f50c83a6b7afddf03/src/Compatibility/Core/src/WPF/Controls/FormsContentControl.cs#L26-L62","documentation":"FormsContentControl.OnContentLoaderChanged throws ArgumentNullException(\"ContentLoader\") when the WPF DependencyProperty is set to null. LightContentControl_SizeChanged immediately dereferences ContentLoader, so null would NRE on the next resize unless rejected here.","triggerScenarios":"Setting FormsContentControl.ContentLoader to null in XAML or code; a binding to ContentLoader that resolves to null; clearing the property without assigning a replacement loader.","commonSituations":"Resource lookup failure for the ContentLoader; DataContext unset so the binding evaluates to null; explicit teardown nulling the loader; loader swap that assigns null before constructing the new loader.","solutions":["Assign a concrete IContentLoader (FormsContentLoader or DefaultContentLoader) before the control measures its content.","Use FallbackValue on the binding so a null source resolves to a default loader.","Never null ContentLoader during teardown; dispose the underlying page instead.","Verify any {StaticResource}/{DynamicResource} reference resolves at runtime."],"exampleFix":"// before\ncontrol.ContentLoader = null;\n\n// after\ncontrol.ContentLoader = new FormsContentLoader();","handlingStrategy":"validation","validationCode":"control.ContentLoader = control.ContentLoader ?? new FormsContentLoader();","typeGuard":"static bool HasValidLoader(FormsContentControl c) => c.ContentLoader != null;","tryCatchPattern":"try { control.ContentLoader = loader; }\ncatch (ArgumentNullException) { control.ContentLoader = new FormsContentLoader(); }","preventionTips":["Provide a default ContentLoader in the control's XAML template.","Use FallbackValue in ContentLoader bindings.","Audit cleanup paths to ensure they never null the property."],"tags":["wpf","dependency-property","argumentnull","content-loader","size-changed"],"backgroundTag":null,"analyzedSha":"f377ff1c5ee04d334d8a925f50c83a6b7afddf03","analyzedAt":"2026-08-13T14:26:18.069Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}