{"record":{"id":"1c32e74a6c2e0a28","repo":"dotnet/maui","slug":"binding","errorCode":null,"errorMessage":"binding","messagePattern":"binding","errorType":"exception","errorClass":"ArgumentNullException","httpStatus":null,"severity":"error","filePath":"src/Controls/src/Core/BindableObject.cs","lineNumber":343,"sourceCode":"\n\t\t\tBindingBase oldBinding = null;\n\t\t\tSetterSpecificity oldSpecificity = default;\n\t\t\tif (context.Bindings.Count > 0)\n\t\t\t{\n\t\t\t\tvar b_p = context.Bindings.GetSpecificityAndValue();\n\t\t\t\toldSpecificity = b_p.Key;\n\t\t\t\toldBinding = b_p.Value;\n\t\t\t}\n\n\t\t\tif (oldBinding != null && specificity < oldSpecificity)\n\t\t\t{\n\t\t\t\tcontext.Bindings[specificity] = binding;\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\toldBinding?.Unapply();\n\n\t\t\tcontext.Bindings[specificity] = binding ?? throw new ArgumentNullException(nameof(binding));\n\n\t\t\ttargetProperty.BindingChanging?.Invoke(this, oldBinding, binding);\n\n\t\t\tbinding.Apply(BindingContext, this, targetProperty, false, specificity);\n\t\t}\n\n\t\t/// <summary>\n\t\t/// Sets the inherited context to a nested element.\n\t\t/// </summary>\n\t\t/// <param name=\"bindable\">The object on which to set the inherited binding context.</param>\n\t\t/// <param name=\"value\">The inherited context to set.</param>\n\t\t/// <remarks>For internal use only. This API can be changed or removed without notice at any time.</remarks>\n\t\t[EditorBrowsable(EditorBrowsableState.Never)]\n\t\tpublic static void SetInheritedBindingContext(BindableObject bindable, object value)\n\t\t{\n\t\t\t// I wonder if we couldn't treat BindingContext with specificities\n\t\t\tBindablePropertyContext bpContext = bindable.GetContext(BindingContextProperty);\n\t\t\tif (bpContext != null && bpContext.Values.GetSpecificity() >= SetterSpecificity.ManualValueSetter)","sourceCodeStart":325,"sourceCodeEnd":361,"githubUrl":"https://github.com/dotnet/maui/blob/f377ff1c5ee04d334d8a925f50c83a6b7afddf03/src/Controls/src/Core/BindableObject.cs#L325-L361","documentation":"Thrown inside the internal SetBinding flow at the line that stores the binding: 'context.Bindings[specificity] = binding ?? throw new ArgumentNullException(nameof(binding));'. Despite the null-coalescing throw, it fires when a null BindingBase reaches the apply step, i.e. SetBinding was effectively asked to register a null binding. Note the public SetBinding allows a null binding through to compute specificity, so this guard is the actual null-binding enforcement point.","triggerScenarios":"Calling SetBinding(targetProperty, null); a binding factory returning null; a conditional binding expression that produced null and was forwarded without a check.","commonSituations":"Conditional UI code that builds a binding only sometimes and passes null otherwise; migrating code that used to call SetBinding with a default and now passes null after a refactor.","solutions":["Do not call SetBinding with a null binding — call RemoveBinding instead if you intended to clear it.","Null-check the binding before calling SetBinding: 'if (binding is not null) target.SetBinding(prop, binding);'.","Fix the binding factory so it never returns null."],"exampleFix":"// before\nobj.SetBinding(prop, maybeNullBinding);\n// after\nif (maybeNullBinding is not null)\n    obj.SetBinding(prop, maybeNullBinding);\nelse\n    obj.RemoveBinding(prop);","handlingStrategy":"validation","validationCode":"if (binding is null) { obj.RemoveBinding(targetProperty); return; }\nobj.SetBinding(targetProperty, binding);","typeGuard":"static bool IsUsableBinding(Microsoft.Maui.Controls.BindingBase b) => b is not null;","tryCatchPattern":"try { obj.SetBinding(prop, binding); }\ncatch (ArgumentNullException ex) when (ex.ParamName == \"binding\")\n{ /* binding was null; clear instead or log */ }","preventionTips":["Use RemoveBinding to clear, never SetBinding(prop, null).","Null-check binding factories before forwarding their result."],"tags":["maui","binding","argument-null","nullable"],"backgroundTag":null,"analyzedSha":"f377ff1c5ee04d334d8a925f50c83a6b7afddf03","analyzedAt":"2026-08-13T14:26:18.069Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}