{"record":{"id":"451be564d45e2c10","repo":"dotnet/maui","slug":"propertykey","errorCode":null,"errorMessage":"propertyKey","messagePattern":"propertyKey","errorType":"exception","errorClass":"ArgumentNullException","httpStatus":null,"severity":"error","filePath":"src/Controls/src/Core/BindableObject.cs","lineNumber":120,"sourceCode":"\t\t\tif (property.IsReadOnly)\n\t\t\t{\n\t\t\t\tApplication.Current?.FindMauiContext()?.CreateLogger<BindableObject>()?.LogWarning($\"Cannot set the BindableProperty \\\"{property.PropertyName}\\\" because it is readonly.\");\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tClearValueCore(property, specificity);\n\t\t}\n\n\t\t/// <summary>\n\t\t/// Clears any value that is previously set for a bindable property, identified by its key.\n\t\t/// </summary>\n\t\t/// <param name=\"propertyKey\">The key that identifies the bindable property to clear the value for.</param>\n\t\t/// <exception cref=\"ArgumentNullException\">Thrown when <paramref name=\"propertyKey\"/> is <see langword=\"null\"/>.</exception>\n\t\t/// <exception cref=\"InvalidOperationException\">Thrown when <paramref name=\"propertyKey\"/> is a read-only property.</exception>\n\t\tpublic void ClearValue(BindablePropertyKey propertyKey)\n\t\t{\n\t\t\tif (propertyKey == null)\n\t\t\t\tthrow new ArgumentNullException(nameof(propertyKey));\n\n\t\t\tClearValueCore(propertyKey.BindableProperty, SetterSpecificity.ManualValueSetter);\n\t\t}\n\n\t\tvoid ClearValueCore(BindableProperty property, SetterSpecificity specificity)\n\t\t{\n\n\t\t\tBindablePropertyContext bpcontext = GetContext(property);\n\t\t\tif (bpcontext == null)\n\t\t\t\treturn;\n\n\t\t\tvar original = bpcontext.Values.GetSpecificityAndValue();\n\t\t\tif (original.Key == SetterSpecificity.FromHandler)\n\t\t\t{\n\t\t\t\tbpcontext.Values.Remove(SetterSpecificity.FromHandler);\n\t\t\t}\n\n\t\t\tvar newValue = bpcontext.Values.GetClearedValue(specificity);","sourceCodeStart":102,"sourceCodeEnd":138,"githubUrl":"https://github.com/dotnet/maui/blob/f377ff1c5ee04d334d8a925f50c83a6b7afddf03/src/Controls/src/Core/BindableObject.cs#L102-L138","documentation":"Thrown by the public BindableObject.ClearValue(BindablePropertyKey) overload when propertyKey is null. The key-based overload exists for read-only bindable properties and dereferences propertyKey.BindableProperty, so a null key is rejected immediately.","triggerScenarios":"Calling ClearValue((BindablePropertyKey)null) or passing a key variable that resolved to null, reaching 'throw new ArgumentNullException(nameof(propertyKey))'.","commonSituations":"Clearing a read-only property whose key field was never assigned; holding a BindablePropertyKey in a dictionary that returns null; refactor that renamed the key field and left the old reference null.","solutions":["Pass the actual BindablePropertyKey returned when the read-only BindableProperty was created (the static readonly field).","Null-check the key before clearing: if (key is not null) obj.ClearValue(key);.","If you only have the BindableProperty, use the property-based ClearValue overload instead."],"exampleFix":"// before\nobj.ClearValue((BindablePropertyKey)null);\n// after\nobj.ClearValue(MyControl.ReadOnlyPropertyKey);","handlingStrategy":"validation","validationCode":"static void SafeClearKey(BindableObject obj, BindablePropertyKey? key)\n{\n    if (key is null) return;\n    obj.ClearValue(key);\n}","typeGuard":"static bool IsValidKey(BindablePropertyKey? k) => k is not null;","tryCatchPattern":null,"preventionTips":["Use the static readonly BindablePropertyKey field created alongside the read-only property.","Null-check the key before clearing when the source may be absent.","If you only hold the BindableProperty, use the property-based ClearValue overload instead."],"tags":["bindable-object","null-argument","clearvalue","readonly-key"],"backgroundTag":null,"analyzedSha":"f377ff1c5ee04d334d8a925f50c83a6b7afddf03","analyzedAt":"2026-08-13T14:26:18.069Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}