dotnet/maui · error · ArgumentNullException
property
Error message
property
What it means
Thrown by the public BindableObject.ClearValue(BindableProperty) overload when the property argument is null. The method guards its precondition up front because every subsequent step (IsReadOnly check, ClearValueCore) needs a real BindableProperty to key the value store.
Source
Thrown at src/Controls/src/Core/BindableObject.cs:86
/// Occurs when a property value is changing.
/// </summary>
public event PropertyChangingEventHandler PropertyChanging;
/// <summary>
/// Occurs when the value of the <see cref="BindingContext"/> property changes.
/// </summary>
public event EventHandler BindingContextChanged;
/// <summary>
/// Clears any value that is previously set for a bindable property.
/// </summary>
/// <param name="property">The <see cref="BindableProperty"/> to clear the value for.</param>
/// <exception cref="ArgumentNullException">Thrown when <paramref name="property"/> is <see langword="null"/>.</exception>
/// <remarks>When <paramref name="property"/> is read-only, nothing will happen.</remarks>
public void ClearValue(BindableProperty property)
{
if (property == null)
throw new ArgumentNullException(nameof(property));
if (property.IsReadOnly)
{
Application.Current?.FindMauiContext()?.CreateLogger<BindableObject>()?.LogWarning($"Cannot set the BindableProperty \"{property.PropertyName}\" because it is readonly.");
return;
}
ClearValueCore(property, SetterSpecificity.ManualValueSetter);
}
internal void ClearValue(BindableProperty property, SetterSpecificity specificity)
{
if (property == null)
throw new ArgumentNullException(nameof(property));
if (property.IsReadOnly)
{
Application.Current?.FindMauiContext()?.CreateLogger<BindableObject>()?.LogWarning($"Cannot set the BindableProperty \"{property.PropertyName}\" because it is readonly.");View on GitHub (pinned to f377ff1c5e)
Solutions
- Pass a concrete, non-null BindableProperty reference (e.g. Label.TextProperty).
- Null-check before calling: if (property is not null) obj.ClearValue(property);.
- Fix the resolver/lookup that produced the null BindableProperty so it always returns a valid field.
Example fix
// before obj.ClearValue(maybeNullProperty); // after if (maybeNullProperty is not null) obj.ClearValue(maybeNullProperty);
Defensive patterns
Strategy: validation
Validate before calling
static void SafeClear(BindableObject obj, BindableProperty? p)
{
if (p is null) return;
obj.ClearValue(p);
} Type guard
static bool IsValidProperty(BindableProperty? p) => p is not null;
Prevention
- Pass concrete BindableProperty fields (e.g. Label.TextProperty), never computed nulls.
- Null-check before ClearValue when the property source may be absent.
- Review generic helpers that resolve BindableProperty to ensure they never return null.
When it happens
Trigger: Calling ClearValue(null) or ClearValue(someExpression) where the expression evaluates to null, hitting 'if (property == null) throw new ArgumentNullException(nameof(property))'.
Common situations: Passing a BindableProperty field that was never initialized or was nulled out; computing the property from a dictionary/lookup that can return null; clearing inside a generic helper where T's property resolver returned null.
Related errors
AI-assisted analysis of dotnet/maui@f377ff1c5e (2026-08-13).
Data as JSON: /api/errors/0df98ebcb320245b.
Report an issue: GitHub.