{"record":{"id":"ef9342357f2fbbbc","repo":"dotnet/wpf","slug":"sr-incorrectsetterparamnum","errorCode":null,"errorMessage":"SR.IncorrectSetterParamNum","messagePattern":"SR\\.IncorrectSetterParamNum","errorType":"validation","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/System.Xaml/System/Xaml/XamlMember.cs","lineNumber":857,"sourceCode":"\n        private static void ValidateGetter(MethodInfo method, string argumentName)\n        {\n            if (method is null)\n            {\n                return;\n            }\n\n            if ((method.GetParameters().Length != 1) || (method.ReturnType == typeof(void)))\n            {\n                throw new ArgumentException(SR.IncorrectGetterParamNum, argumentName);\n            }\n        }\n\n        private static void ValidateSetter(MethodInfo method, string argumentName)\n        {\n            if ((method is not null) && (method.GetParameters().Length != 2))\n            {\n                throw new ArgumentException(SR.IncorrectSetterParamNum, argumentName);\n            }\n        }\n\n        // This property needs to be checked before any attribute lookups on _reflector. It's not\n        // only informational, it also ensures that the right state is initialized.\n        private bool AreAttributesAvailable\n        {\n            get\n            {\n                EnsureReflector();\n\n                // Make sure that AttributeProvider is initialized\n                // Note: Don't short-circuit the AttributeProvider lookup, even if UnderlyingMember\n                // is non-null; a derived class can use AttributeProvider to override attribute lookup\n\n                // Volatile read/write of CustomAttributeProvider to make sure that threads that see\n                // CustomAttributeProviderIsSet == true also see the write to _reflector.UnderlyingMember\n                if (!_reflector.CustomAttributeProviderIsSetVolatile)","sourceCodeStart":839,"sourceCodeEnd":875,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/System.Xaml/System/Xaml/XamlMember.cs#L839-L875","documentation":"ValidateSetter rejects setter MethodInfo objects that do not have exactly two parameters, throwing ArgumentException with SR.IncorrectSetterParamNum. An attachable setter must be static void SetX(object target, TValue value).","triggerScenarios":"Constructing an attachable-property XamlMember or attachable-event XamlMember with a setter/adder MethodInfo whose parameter count is not 2.","commonSituations":"Attached-event Add handlers missing the sender parameter, or setters written as instance methods with one value parameter.","solutions":["Change the setter to have exactly two parameters: (object target, TValue value).","Pass a correct MethodInfo instead.","Pass null for the setter if only a getter is intended."],"exampleFix":"// before\npublic static void SetMyProp(string value) { ... }\n// after\npublic static void SetMyProp(object target, string value) { ... }","handlingStrategy":"validation","validationCode":"if (setter is not null && setter.GetParameters().Length != 2) throw new ArgumentException(\"Setter must take exactly 2 parameters\");","typeGuard":"bool IsValidSetter(MethodInfo m) => m is null || m.GetParameters().Length == 2;","tryCatchPattern":null,"preventionTips":["Write attachable setters as public static void SetX(object owner, T value).","Include the target-object parameter in attached-event add handlers."],"tags":["xaml","argument-exception","method-signature"],"backgroundTag":"invalid-argument-value","analyzedSha":"81131a70a4c573cd62748a5c36908fc4d662daa9","analyzedAt":"2026-09-14T10:12:48.479Z","contentChangedAt":"2026-09-14T10:12:48.479Z","schemaVersion":2},"datasetVersion":"2026-09-21T21:30:21.729Z"}