dotnet/maui · error · ArgumentNullException
targetProperty
Error message
targetProperty
What it means
Thrown by the public BindableObject.IsSet(BindableProperty) when targetProperty is null. The method uses an inline null-coalescing throw (GetContext(targetProperty ?? throw new ArgumentNullException(nameof(targetProperty)))) because it needs a real property to look up the value context.
Source
Thrown at src/Controls/src/Core/BindableObject.cs:248
{
var pair = context.Values.GetSpecificityAndValue();
result.IsSet = pair.Key != SetterSpecificity.DefaultValue;
result.Value = (T)pair.Value;
}
}
return resultArray;
}
/// <summary>
/// Determines whether or not a bindable property exists and has a value set.
/// </summary>
/// <param name="targetProperty">The bindable property to check if a value is currently set.</param>
/// <returns><see langword="true"/> if the target property exists and has been set. Otherwise <see langword="false"/>.</returns>
/// <exception cref="ArgumentNullException">Thrown when <paramref name="targetProperty"/> is <see langword="null"/>.</exception>
public bool IsSet(BindableProperty targetProperty)
{
var bpcontext = GetContext(targetProperty ?? throw new ArgumentNullException(nameof(targetProperty)));
if (bpcontext == null)
return false;
if ((bpcontext.Attributes & BindableContextAttributes.IsDefaultValueCreated) == BindableContextAttributes.IsDefaultValueCreated)
return true;
return bpcontext.Values.GetSpecificity() != SetterSpecificity.DefaultValue;
}
/// <summary>
/// Determines whether a bindable property has been set by a local value, style, binding, or other non-default specificity.
/// Unlike IsSet, default-value creation does not count as explicit.
/// </summary>
/// <param name="targetProperty">The bindable property to check if a value is explicitly set.</param>
/// <returns><see langword="true"/> if the target property exists and has been explicitly set. Otherwise <see langword="false"/>.</returns>
/// <exception cref="ArgumentNullException">Thrown when <paramref name="targetProperty"/> is <see langword="null"/>.</exception>
internal bool IsSetExplicitly(BindableProperty targetProperty)
{
var bpcontext = GetContext(targetProperty ?? throw new ArgumentNullException(nameof(targetProperty)));
return bpcontext is not null && bpcontext.Values.GetSpecificity() != SetterSpecificity.DefaultValue;View on GitHub (pinned to f377ff1c5e)
Solutions
- Pass a non-null BindableProperty (e.g. VisualElement.IsVisibleProperty).
- Guard the call: if (prop is not null && obj.IsSet(prop)) { ... }.
- Resolve the BindableProperty from the correct type so it is never null.
Example fix
// before bool set = obj.IsSet(maybeNullProp); // after bool set = maybeNullProp is not null && obj.IsSet(maybeNullProp);
Defensive patterns
Strategy: validation
Validate before calling
static bool SafeIsSet(BindableObject obj, BindableProperty? p)
=> p is not null && obj.IsSet(p); Type guard
static bool IsValidProperty(BindableProperty? p) => p is not null;
Prevention
- Resolve BindableProperty from the correct type so it is never null.
- Null-check before IsSet when the source may be absent.
- Prefer the public IsSet API over reflective lookups in application code.
When it happens
Trigger: Calling IsSet(null) or IsSet(prop) where prop evaluates to null, so the '?? throw' expression fires.
Common situations: Checking whether a property is set via a resolver that returned null; guarding against a property that may not exist on the current type; passing a BindableProperty from another type by mistake.
Related errors
AI-assisted analysis of dotnet/maui@f377ff1c5e (2026-08-13).
Data as JSON: /api/errors/d0fe00edff894709.
Report an issue: GitHub.