{"record":{"id":"7f35ea9f4a53325e","repo":"dotnet/wpf","slug":"sr-cannotdeterminesortbypropertiesforcollection","errorCode":null,"errorMessage":"SR.CannotDetermineSortByPropertiesForCollection","messagePattern":"SR\\.CannotDetermineSortByPropertiesForCollection","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Data/BindingListCollectionView.cs","lineNumber":2195,"sourceCode":"            PropertyDescriptorCollection pdc;\n            ITypedList itl;\n            Type itemType;\n\n            if ((itl = InternalList as ITypedList) != null)\n            {\n                pdc = itl.GetItemProperties(null);\n            }\n            else if ((itemType = GetItemType(true)) != null)\n            {\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","sourceCodeStart":2177,"sourceCodeEnd":2213,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Data/BindingListCollectionView.cs#L2177-L2213","documentation":"When converting WPF SortDescriptions to .NET ListSortDescriptions for a BindingListCollectionView, the view obtains the item property descriptors from the source list. If it cannot determine any sort-by properties (the item type has no properties, or the list provides no item type information), it throws ArgumentException with SR.CannotDetermineSortByPropertiesForCollection.","triggerScenarios":"Calling view.SortDescriptions.Add(...) (or CustomSort-free sorting) on a BindingListCollectionView whose source is a list of a type with no public instance properties, or whose IBindingList/ITypedList cannot supply a PropertyDescriptorCollection (e.g. list of primitives, empty list with no type info, non-ITypedList custom list of object).","commonSituations":"Binding to List<int>, List<string> or other primitive collections and then setting SortDescriptions with a property path; binding to an empty collection whose item type cannot be reflected; DataGrid column auto-sorting over such a source.","solutions":["Sort the underlying collection directly (e.g. with OrderBy and reassign) instead of using SortDescriptions.","Bind to a collection of a type with public properties (a view-model or row type) so property descriptors can be resolved.","Implement ITypedList on the custom list to supply the item PropertyDescriptorCollection.","For empty collections, pre-populate or use a typed view-model collection so reflection can find properties."],"exampleFix":"// before\nvar view = (BindingListCollectionView)CollectionViewSource.GetDefaultView(new List<int>());\nview.SortDescriptions.Add(new SortDescription(\"Value\", ListSortDirection.Ascending)); // throws\n\n// after\nvar source = new ObservableCollection<MyRow>();\nvar view2 = CollectionViewSource.GetDefaultView(source);\nview2.SortDescriptions.Add(new SortDescription(\"Value\", ListSortDirection.Ascending));","handlingStrategy":"validation","validationCode":"var props = item != null ? TypeDescriptor.GetProperties(item.GetType()) : null;\nif (props == null || props.Count == 0)\n    throw new InvalidOperationException(\"item type exposes no sortable properties\");","typeGuard":"bool isSortableCollection<T>(IEnumerable<T> c) => typeof(T).GetProperties(BindingFlags.Public | BindingFlags.Instance).Length > 0;","tryCatchPattern":"try { view.SortDescriptions.Add(sd); }\ncatch (ArgumentException) { /* sort the underlying collection directly */ }","preventionTips":["Avoid SortDescriptions on collections of primitives","Bind to typed view-model collections, not List<object>","Implement ITypedList on custom lists to expose item properties"],"tags":["wpf","data-binding","sorting","argument","property-descriptor"],"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"}