dotnet/wpf · error · ArgumentNullException
SR.GetterOrSetterRequired
Error message
SR.GetterOrSetterRequired
What it means
The attachable-member XamlMember constructor requires at least one of 'getter' or 'setter' to be a non-null MethodInfo. When both are null it throws ArgumentNullException whose message is SR.GetterOrSetterRequired. Without an accessor the member cannot be read or written.
Solutions
- Pass at least one valid accessor MethodInfo (getter or setter).
- Fix the reflection lookup (method name must be 'Get<Name>'/'Set<Name>' and public static) so an accessor is found.
- Verify you are not accidentally passing variables that were assigned null earlier.
Example fix
// before
var member = new XamlMember("MyAttached", null, null, schemaContext, invoker, reflector);
// after
var getter = declaringType.GetMethod("GetMyAttached", BindingFlags.Public | BindingFlags.Static);
var member = new XamlMember("MyAttached", getter, null, schemaContext, invoker, reflector); Defensive patterns
Strategy: validation
Validate before calling
if (getter is null && setter is null) throw new ArgumentException("At least one of getter or setter is required"); Type guard
bool HasAccessor(MethodInfo g, MethodInfo s) => g is not null || s is not null;
Prevention
- Verify reflection lookups for Get/Set accessors return non-null before constructing.
- Log accessor lookups to catch broken naming conventions (Get<Name>/Set<Name>).
When it happens
Trigger: Calling new XamlMember(attachablePropertyName, getter: null, setter: null, schemaContext, invoker, reflector) — i.e. both accessor MethodInfos are null.
Common situations: Reflecting attachable properties where the getter and setter are discovered via reflection (e.g. Type.GetMethod with loose binding flags) and neither lookup matched.
Understand the failure class
Background: "missing required argument" and "the following required arguments were not provided": what required-argument errors mean and how to fix them — this error's family across 20 libraries.
Related errors
- ' '.' ' is a property without a getter and is not a valid…
- ' '.' ' is a property without a getter and is not a valid…
- ' '.' ' is a property without a getter and is not a valid…
- ArgumentNullException(nameof(arrayType))
- ArgumentNullException(nameof(clrNamespace))
AI-assisted analysis of dotnet/wpf@81131a70a4 (2026-09-14).
Data as JSON: /api/errors/0983f9c22c75f3ee.
Report an issue: GitHub.
Appendix: source
Thrown at src/Microsoft.DotNet.Wpf/src/System.Xaml/System/Xaml/XamlMember.cs:107
XamlSchemaContext schemaContext)
:this(attachablePropertyName, getter, setter, schemaContext, null)
{
}
public XamlMember(string attachablePropertyName, MethodInfo getter, MethodInfo setter,
XamlSchemaContext schemaContext, XamlMemberInvoker invoker)
:this(attachablePropertyName, getter, setter, schemaContext, invoker, new MemberReflector(getter, setter, isEvent: false))
{
}
internal XamlMember(string attachablePropertyName, MethodInfo getter, MethodInfo setter,
XamlSchemaContext schemaContext, XamlMemberInvoker invoker, MemberReflector reflector)
{
ArgumentNullException.ThrowIfNull(schemaContext);
MethodInfo accessor = getter ?? setter;
if (accessor is null)
{
throw new ArgumentNullException(SR.GetterOrSetterRequired, (Exception)null);
}
_name = attachablePropertyName ?? throw new ArgumentNullException(nameof(attachablePropertyName));
ValidateGetter(getter, nameof(getter));
ValidateSetter(setter, nameof(setter));
_declaringType = schemaContext.GetXamlType(accessor.DeclaringType);
_reflector = reflector;
_memberType = MemberType.Attachable;
_reflector.Invoker = invoker;
_underlyingMember.Value = getter ?? setter;
}
// Known attachable event
public XamlMember(string attachableEventName, MethodInfo adder, XamlSchemaContext schemaContext)
:this(attachableEventName, adder, schemaContext, null)
{View on GitHub (pinned to 81131a70a4)