{"record":{"id":"d1a5adb8629ea07b","repo":"dotnet/wpf","slug":"sr-format-sr-propertypathinvalidaccessor-accessor-null","errorCode":null,"errorMessage":"SR.Format(SR.PropertyPathInvalidAccessor, (accessor != null) ? accessor.GetType().FullName : \"null\")","messagePattern":"SR\\.Format\\(SR\\.PropertyPathInvalidAccessor, \\(accessor != null\\) \\? accessor\\.GetType\\(\\)\\.FullName : \"null\"\\)","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/PropertyPath.cs","lineNumber":554,"sourceCode":"            }\n        }\n\n        // resolve a single DP name\n        private object ResolvePropertyName(string name, object item, Type ownerType, object context, bool throwOnError)\n        {\n            string propertyName = name;\n            int index;\n\n            // first see if the name is an index into the parameter list\n            if (IsParameterIndex(name, out index))\n            {\n                if (0 <= index && index < PathParameters.Count)\n                {\n                    object accessor = PathParameters[index];\n                    // always throw if the accessor isn't valid - this error cannot\n                    // be corrected later on.\n                    if (!IsValidAccessor(accessor))\n                        throw new InvalidOperationException(SR.Format(SR.PropertyPathInvalidAccessor,\n                                    (accessor != null) ? accessor.GetType().FullName : \"null\"));\n\n                    return accessor;\n                }\n                else if (throwOnError)\n                    throw new InvalidOperationException(SR.Format(SR.PathParametersIndexOutOfRange, index, PathParameters.Count));\n                else return null;\n            }\n\n            // handle attached-property syntax:  (TypeName.PropertyName)\n            if (IsPropertyReference(name))\n            {\n                name = name.Substring(1, name.Length-2);\n\n                int lastIndex = name.LastIndexOf('.');\n                if (lastIndex >= 0)\n                {\n                    // attached property - get the owner type","sourceCodeStart":536,"sourceCodeEnd":572,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/PropertyPath.cs#L536-L572","documentation":"PropertyPath.ResolvePropertyName throws this InvalidOperationException when a path parameter at the given index is not a valid property accessor. WPF accepts only PropertyInfo, MethodInfo (getter), or DependencyProperty objects (IsValidAccessor) as accessors in PathParameters, and since an invalid accessor cannot be corrected later during binding evaluation, the path construction fails immediately.","triggerScenarios":"Building a PropertyPath whose path string references an indexed parameter '(n)' where PathParameters[n] was populated with an arbitrary object (e.g. a string or custom type) rather than PropertyInfo, MethodInfo, or DependencyProperty; or programmatically inserting a non-accessor object into PathParameters before the path is resolved.","commonSituations":"Hand-constructing PropertyPath objects with PathParameters instead of passing named properties; passing a reflection MemberInfo of the wrong member kind (e.g. FieldInfo or ConstructorInfo); WPF version changes tightening accessor validation; mistakenly believing any object resolving the property is accepted.","solutions":["Inspect PathParameters[index] and replace the object with a PropertyInfo from Type.GetProperty, a DependencyProperty field, or a MethodInfo for the property getter","If you intended a plain property name, remove the '(n)' indexed-parameter syntax from the path string and use the property name directly","Verify with PropertyPath.IsValidState/IsValidAccessor logic that every entry in PathParameters is one of the three accepted accessor kinds","Use the string-based PropertyPath constructor with a ParserContext so WPF resolves accessors itself instead of supplying them manually"],"exampleFix":"// before\nvar path = new PropertyPath(\"(0).Name\");\npath.PathParameters.Add(\"Name\"); // string, not an accessor\n// after\nvar path = new PropertyPath(\"(0).Name\");\npath.PathParameters.Add(typeof(Person).GetProperty(\"Name\")); // PropertyInfo accessor","handlingStrategy":"validation","validationCode":"static bool IsValidPathAccessor(object a) =>\n    a == null || a is System.Reflection.PropertyInfo || a is System.Reflection.MethodInfo || a is System.Windows.DependencyProperty;\n// check: PathParameters.All(IsValidPathAccessor)","typeGuard":"bool IsPropertyInfo(object o) => o is System.Reflection.PropertyInfo;","tryCatchPattern":"try { var accessor = path.ResolvePropertyName(i, item, ctx, true); }\ncatch (InvalidOperationException ex) when (ex.Message.Contains(\"accessor\")) { /* replace accessor in PathParameters */ }","preventionTips":["Only add PropertyInfo, MethodInfo, or DependencyProperty objects to PathParameters","Prefer string-based paths with a ParserContext over manual accessor lists","Unit-test every PropertyPath you build programmatically before shipping"],"tags":["wpf","binding","property-path","invalid-accessor","invalid-argument-value"],"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"}