{"record":{"id":"1f7848a5a2f1e466","repo":"dotnet/maui","slug":"self-1f7848","errorCode":null,"errorMessage":"self","messagePattern":"self","errorType":"exception","errorClass":"ArgumentNullException","httpStatus":null,"severity":"error","filePath":"src/Controls/src/Core/BindableObjectExtensions.cs","lineNumber":65,"sourceCode":"\n\t\t\t\tsetChildBindingContext(bo, bc);\n\t\t\t}\n\t\t}\n\n\t\t/// <summary>Creates and applies a binding to a property.</summary>\n\t\t/// <param name=\"self\">The <see cref=\"Microsoft.Maui.Controls.BindableObject\"/>.</param>\n\t\t/// <param name=\"targetProperty\">The BindableProperty on which to set a binding.</param>\n\t\t/// <param name=\"path\">A <see cref=\"System.String\"/> indicating the property path to bind to.</param>\n\t\t/// <param name=\"mode\">The <see cref=\"Microsoft.Maui.Controls.BindingMode\"/> for the binding. This parameter is optional. Default is <see cref=\"Microsoft.Maui.Controls.BindingMode.Default\"/>.</param>\n\t\t/// <param name=\"converter\">An <see cref=\"Microsoft.Maui.Controls.IValueConverter\"/> for the binding. This parameter is optional. Default is <see langword=\"null\"/>.</param>\n\t\t/// <param name=\"stringFormat\">A string used as stringFormat for the binding. This parameter is optional. Default is <see langword=\"null\"/>.</param>\n\t\t/// <remarks>The following example shows how to use the extension method to set a binding.</remarks>\n\t\t[RequiresUnreferencedCode(TrimmerConstants.StringPathBindingWarning, Url = TrimmerConstants.ExpressionBasedBindingsDocsUrl)]\n\t\tpublic static void SetBinding(this BindableObject self, BindableProperty targetProperty, string path, BindingMode mode = BindingMode.Default, IValueConverter converter = null,\n\t\t\t\t\t\t\t\t\t  string stringFormat = null)\n\t\t{\n\t\t\tif (self == null)\n\t\t\t\tthrow new ArgumentNullException(nameof(self));\n\t\t\tif (targetProperty == null)\n\t\t\t\tthrow new ArgumentNullException(nameof(targetProperty));\n\n\t\t\tvar binding = new Binding(path, mode, converter, stringFormat: stringFormat);\n\t\t\tself.SetBinding(targetProperty, binding);\n\t\t}\n\n#nullable enable\n\t\t/// <summary>\n\t\t/// Creates a binding between a property on the source object and a property on the target object.\n\t\t/// </summary>\n\t\t/// <remarks>\n\t\t///   <para>The following example illustrates the setting of a binding using the extension method.</para>\n\t\t///   <example>\n\t\t///     <code lang=\"csharp lang-csharp\"><![CDATA[\n\t\t///      public class PersonViewModel\n\t\t///      {\n\t\t///          public string Name { get; set; }","sourceCodeStart":47,"sourceCodeEnd":83,"githubUrl":"https://github.com/dotnet/maui/blob/f377ff1c5ee04d334d8a925f50c83a6b7afddf03/src/Controls/src/Core/BindableObjectExtensions.cs#L47-L83","documentation":"Thrown by the BindableObjectExtensions.SetBinding(this BindableObject, BindableProperty, string, ...) extension method when self (the BindableObject) is null. This string-path overload builds a Binding from the path and forwards to instance.SetBinding; the guard prevents a NullReferenceException when constructing/invoking the binding.","triggerScenarios":"Calling SetBinding as an extension on a null BindableObject, e.g. '((Entry)null).SetBinding(Entry.TextProperty, \"Foo\");'; a view that was not yet created; a cell/control returned null from FindByName/GetTemplateChild.","commonSituations":"XAML code-behind referencing a control before InitializeComponent or with a wrong x:Name; data-template child lookups returning null; conditional UI where the target was conditionally instantiated.","solutions":["Ensure the BindableObject target is non-null before calling the extension (verify x:Name and initialization order).","Null-check the target: 'if (view is not null) view.SetBinding(prop, path);'.","Confirm FindByName/GetTemplateChild returns the expected control."],"exampleFix":"// before\nnameField.SetBinding(Entry.TextProperty, nameof(vm.Name));\n// after\nif (nameField is not null)\n    nameField.SetBinding(Entry.TextProperty, nameof(vm.Name));","handlingStrategy":"validation","validationCode":"if (self is null) throw new InvalidOperationException(\"target BindableObject is null\");\nself.SetBinding(targetProperty, path);","typeGuard":"static bool IsUsableTarget(Microsoft.Maui.Controls.BindableObject o) => o is not null;","tryCatchPattern":null,"preventionTips":["Verify x:Name targets resolve and that InitializeComponent ran before binding in code-behind.","Null-check controls returned from FindByName/GetTemplateChild."],"tags":["maui","binding","argument-null","extension-method","nullable"],"backgroundTag":null,"analyzedSha":"f377ff1c5ee04d334d8a925f50c83a6b7afddf03","analyzedAt":"2026-08-13T14:26:18.069Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}