{"record":{"id":"fc8a760817bac499","repo":"dotnet/wpf","slug":"attached-property-setter-and-attached-event-adder-methods","errorCode":null,"errorMessage":"Attached property setter and attached event adder methods must have two parameters.","messagePattern":"Attached property setter and attached event adder methods must have two parameters\\.","errorType":"exception","errorClass":"XamlSchemaException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/System.Xaml/System/Xaml/Schema/ClrAttachableProperty.cs","lineNumber":76,"sourceCode":"\n        private Type PrivateLookupSystemTypeOfProperty\n        {\n            get \n            {\n                if (ClrBindingGetterMethodInfo != null)\n                {\n                    return ClrBindingGetterMethodInfo.ReturnType;\n                }\n                else\n                {\n                    ParameterInfo[] pis = ClrBindingSetterMethodInfo.GetParameters();\n                    if (pis.Length > 1)\n                    {\n                        return ClrBindingSetterMethodInfo.GetParameters()[1].ParameterType;\n                    }\n                    else\n                    {\n                        throw new XamlSchemaException(SR.Format(SR.IncorrectSetterParamNum, ClrBindingSetterMethodInfo.Name, 2));\n                    }\n                }\n            }\n        }\n\n        protected override object[] LookupCustomAttributes(Type attrType)\n        {\n            if (ClrBindingGetterMethodInfo != null)\n            {\n                return ClrBindingGetterMethodInfo.GetCustomAttributes(attrType, true);\n            }\n            return ClrBindingSetterMethodInfo.GetCustomAttributes(attrType, true);\n        }\n\n        protected override XamlType LookupTargetType()\n        {\n            MethodInfo mi = (ClrBindingGetterMethodInfo != null)\n                ? ClrBindingGetterMethodInfo ","sourceCodeStart":58,"sourceCodeEnd":94,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/System.Xaml/System/Xaml/Schema/ClrAttachableProperty.cs#L58-L94","documentation":"System.Xaml requires attachable property setters and attached event adder methods to take exactly two parameters (the target object and the value/event-handler). When the resolved setter MethodInfo has only one parameter, the schema throws this XamlSchemaException while computing the setter's parameter type.","triggerScenarios":"ClrAttachedProperty resolves ClrBindingSetterMethodInfo whose GetParameters() has Length <= 1, then indexing parameters[1] fails and SR.IncorrectSetterParamNum is thrown with the method name and expected count 2.","commonSituations":"Hand-written Set<Name>(value) methods missing the target-object first parameter; attached-event add handlers written with one argument instead of (object, handler); partial refactors that dropped the target parameter.","solutions":["Change the setter/adder signature to (object target, Type value) — two parameters — e.g. SetFoo(DependencyObject o, MyType value).","Add the missing target-object parameter to the Set<Name> or Add<Name>Handler method.","Point the schema registration at the correct MethodInfo overload that has two parameters."],"exampleFix":"// before\npublic static void SetGlow(double value) { ... }\n// after\npublic static void SetGlow(DependencyObject target, double value) { ... }","handlingStrategy":"validation","validationCode":"// verify attached setter/adder arity before registration\nvar p = setterMethodInfo.GetParameters();\nif (p.Length != 2)\n    throw new InvalidOperationException($\"{setterMethodInfo.Name} must take (target, value): found {p.Length} params\");","typeGuard":"bool IsValidAttachedSetter(MethodInfo m) =>\n    m.IsStatic && m.GetParameters().Length == 2;","tryCatchPattern":"try { member = new ClrAttachedProperty(name, declaringType, getter, setter); }\ncatch (XamlSchemaException ex) { log($\"Bad attached member signature: {ex.Message}\"); }","preventionTips":["Always declare attached setters as static with (DependencyObject target, TValue value).","Match attached event adder signatures to (object sender, THandler handler).","Add signature checks to your schema bootstrap tests."],"tags":["xaml","schema","method-signature"],"backgroundTag":"missing-required-argument","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"}