dotnet/wpf · error · ArgumentException
SR.IncorrectGetterParamNum
Error message
SR.IncorrectGetterParamNum
What it means
ValidateGetter rejects getter MethodInfo objects that do not have exactly one parameter and a non-void return type, throwing ArgumentException with SR.IncorrectGetterParamNum. A valid attachable getter must take the owning object and return the value.
Solutions
- Change the getter to accept exactly one parameter (the object) and return the property value.
- Pass a different, correct MethodInfo.
- If only a setter is valid, omit the getter by passing null instead of an invalid one.
Example fix
// before
public static void GetMyProp(object o) { ... } // void return
// after
public static string GetMyProp(object o) { return ...; } Defensive patterns
Strategy: validation
Validate before calling
if (getter is not null && (getter.GetParameters().Length != 1 || getter.ReturnType == typeof(void))) throw new ArgumentException("Getter must take 1 parameter and return non-void"); Type guard
bool IsValidGetter(MethodInfo m) => m is null || (m.GetParameters().Length == 1 && m.ReturnType != typeof(void));
Prevention
- Write attachable getters as public static T GetX(object owner).
- Validate method signatures with unit tests after refactors.
When it happens
Trigger: Constructing an attachable-property XamlMember with a getter MethodInfo whose GetParameters().Length != 1 or whose ReturnType == typeof(void).
Common situations: Hand-written or code-generated Get<Property> methods with wrong arity or void return, often after signature refactors.
Understand the failure class
Background: "Must be a positive integer", "Invalid value", "Unsupported": the invalid-argument-value error family, when a library rejects the value you pass — this error's family across 35 libraries.
Related errors
- SR.IncorrectSetterParamNum
- Attached property setter and attached event adder methods…
- SR.CanOnlyHaveOneChild
- SR.CanOnlyHaveOneChild
- SR.Format(SR.ParserPrefixNSProperty, nsPrefix, nameString)
AI-assisted analysis of dotnet/wpf@81131a70a4 (2026-09-14).
Data as JSON: /api/errors/2d1ce1baa68b628d.
Report an issue: GitHub.
Appendix: source
Thrown at src/Microsoft.DotNet.Wpf/src/System.Xaml/System/Xaml/XamlMember.cs:849
{
result = LookupIsWritePublic();
_reflector.SetFlag(BoolMemberBits.WritePublic, result.Value);
}
return result.Value;
}
}
private static void ValidateGetter(MethodInfo method, string argumentName)
{
if (method is null)
{
return;
}
if ((method.GetParameters().Length != 1) || (method.ReturnType == typeof(void)))
{
throw new ArgumentException(SR.IncorrectGetterParamNum, argumentName);
}
}
private static void ValidateSetter(MethodInfo method, string argumentName)
{
if ((method is not null) && (method.GetParameters().Length != 2))
{
throw new ArgumentException(SR.IncorrectSetterParamNum, argumentName);
}
}
// This property needs to be checked before any attribute lookups on _reflector. It's not
// only informational, it also ensures that the right state is initialized.
private bool AreAttributesAvailable
{
get
{
EnsureReflector();View on GitHub (pinned to 81131a70a4)