{"record":{"id":"04589309b657eb77","repo":"dotnet/wpf","slug":"sr-format-sr-propertytosortbynotfoundontype-typename-sorts-i","errorCode":null,"errorMessage":"SR.Format(SR.PropertyToSortByNotFoundOnType, typeName, sorts[i].PropertyName)","messagePattern":"SR\\.Format\\(SR\\.PropertyToSortByNotFoundOnType, typeName, sorts\\[i\\]\\.PropertyName\\)","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Data/BindingListCollectionView.cs","lineNumber":2204,"sourceCode":"            {\n                pdc = TypeDescriptor.GetProperties(itemType);\n            }\n            else\n            {\n                pdc = null;\n            }\n\n            if ((pdc == null) || (pdc.Count == 0))\n                throw new ArgumentException(SR.CannotDetermineSortByPropertiesForCollection);\n\n            ListSortDescription[] sortDescriptions = new ListSortDescription[sorts.Count];\n            for (int i = 0; i < sorts.Count; i++)\n            {\n                PropertyDescriptor dd = pdc.Find(sorts[i].PropertyName, true);\n                if (dd == null)\n                {\n                    string typeName = itl.GetListName(null);\n                    throw new ArgumentException(SR.Format(SR.PropertyToSortByNotFoundOnType, typeName, sorts[i].PropertyName));\n                }\n                ListSortDescription sd = new ListSortDescription(dd, sorts[i].Direction);\n                sortDescriptions[i] = sd;\n            }\n\n            return new ListSortDescriptionCollection(sortDescriptions);\n        }\n\n        #region Grouping\n\n        // initialization for grouping that should happen before preparing the local array\n        private void InitializeGrouping()\n        {\n            // discard old groups\n            _group.Clear();\n\n            // initialize the synthetic top level group\n            _group.Initialize();","sourceCodeStart":2186,"sourceCodeEnd":2222,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Data/BindingListCollectionView.cs#L2186-L2222","documentation":"While converting SortDescriptions, each PropertyName is looked up in the item type's PropertyDescriptorCollection. If a requested property does not exist on the item type (descriptor lookup returns null), the view throws ArgumentException with SR.PropertyToSortByNotFoundOnType, naming the list type and the missing property.","triggerScenarios":"Adding a SortDescription whose PropertyName matches no public property of the collection's item type — e.g. a typo ('Nmae' vs 'Name'), a binding-path expression unsupported for sorting (dotted/indexed paths on IBindingListView), or sorting a property that exists only on a derived type.","commonSituations":"Renaming a model property without updating the sort description or XAML; sorting on attached/complex paths against a DataView-backed source; sort strings built dynamically from user input that don't match the schema.","solutions":["Correct the SortDescription PropertyName to match a public property of the item type exactly (case-insensitive).","Validate property names against the item type (TypeDescriptor.GetProperties(itemType)) before adding sort descriptions.","Only sort on properties present on the base item type declared by the list.","If dynamic sorting is needed, use a typed collection with ListCollectionView instead of BindingListCollectionView."],"exampleFix":"// before\nview.SortDescriptions.Add(new SortDescription(\"Nmae\", ListSortDirection.Ascending));\n\n// after\nvar prop = TypeDescriptor.GetProperties(typeof(Customer)).Find(\"Name\", true);\nif (prop != null)\n    view.SortDescriptions.Add(new SortDescription(\"Name\", ListSortDirection.Ascending));","handlingStrategy":"validation","validationCode":"var props = TypeDescriptor.GetProperties(itemType);\nbool exists = props.Find(propertyName, true) != null;\nif (!exists) throw new ArgumentException($\"Property '{propertyName}' not found on {itemType.Name}\");","typeGuard":"bool propertyExists(Type t, string name) => t.GetProperty(name, BindingFlags.Public | BindingFlags.Instance | BindingFlags.IgnoreCase) != null;","tryCatchPattern":"try { view.SortDescriptions.Add(sd); }\ncatch (ArgumentException ex) { log.Warn($\"invalid sort property: {ex.Message}\"); }","preventionTips":["Validate sort property names against TypeDescriptor before applying","Keep sort strings in sync with model property renames","Never pass unvalidated user input as PropertyName"],"tags":["wpf","data-binding","sorting","property-not-found","argument"],"backgroundTag":"resource-not-found","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"}