unoplatform/uno · error · ArgumentNullException
instance
Error message
instance
What it means
Thrown by XamlMemberInvoker.GetValue/SetValue when the instance argument is null (after the unknown-member check passes). The invoker must reflect over a concrete target object to read or write the member, so a null instance is invalid.
Source
Thrown at src/SourceGenerators/System.Xaml/System.Xaml.Schema/XamlMemberInvoker.cs:68
public MethodInfo UnderlyingGetter {
get { return member != null ? member.UnderlyingGetter : null; }
}
public MethodInfo UnderlyingSetter {
get { return member != null ? member.UnderlyingSetter : null; }
}
void ThrowIfUnknown ()
{
if (member == null)
throw new NotSupportedException ("Current operation is invalid for unknown member.");
}
public virtual object GetValue (object instance)
{
ThrowIfUnknown ();
if (instance == null)
throw new ArgumentNullException ("instance");
if (member is XamlDirective)
throw new NotSupportedException (String.Format (CultureInfo.InvariantCulture, "not supported operation on directive member {0}", member));
if (UnderlyingGetter == null)
throw new NotSupportedException (String.Format (CultureInfo.InvariantCulture, "Attempt to get value from write-only property or event {0}", member));
return UnderlyingGetter.Invoke (instance, Array.Empty<object>());
}
public virtual void SetValue (object instance, object value)
{
ThrowIfUnknown ();
if (instance == null)
throw new ArgumentNullException ("instance");
if (member is XamlDirective)
throw new NotSupportedException (String.Format (CultureInfo.InvariantCulture, "not supported operation on directive member {0}", member));
if (UnderlyingSetter == null)
throw new NotSupportedException (String.Format (CultureInfo.InvariantCulture, "Attempt to set value from read-only property {0}", member));
if (member.IsAttachable)
UnderlyingSetter.Invoke (null, new object [] {instance, value});
elseView on GitHub (pinned to 0418340488)
Solutions
- Ensure the owning instance is non-null before invoking, e.g. skip or queue the operation until the instance is realized.
- For attached members, confirm the target element was created in the visual/logical tree.
- Add a null guard at the call site to fail with a domain-specific message.
Example fix
// before
invoker.SetValue(target, value); // throws if target null
// after
if (target != null)
invoker.SetValue(target, value);
else
_pendingSets.Enqueue((invoker, value)); Defensive patterns
Strategy: validation
Validate before calling
if (instance == null)
throw new InvalidOperationException("owning instance not realized");
invoker.SetValue(instance, value); Type guard
static bool HasInstance(object o) => o != null;
Prevention
- Ensure parent instances are constructed before issuing SetValue/GetValue.
- For attached members, confirm the target element exists in the tree.
- Queue operations whose target is not yet realized rather than passing null.
When it happens
Trigger: Calling invoker.GetValue(null) or invoker.SetValue(null, value) where the owning object was not supplied, e.g. processing an attached property against a null parent.
Common situations: XAML readers that emit SetValue calls before the parent object is constructed; tree-walking code that hits a null node; deferred loading where the instance is not yet realized.
Related errors
- member
- Current operation is invalid for unknown member.
- not supported operation on directive member {0}
- Attempt to get value from write-only property or event {0}
- typeName
AI-assisted analysis of unoplatform/uno@0418340488 (2026-08-13).
Data as JSON: /api/errors/056c414727a0a7d9.
Report an issue: GitHub.