dotnet/wpf · error · ArgumentException

SR.Format(SR.PropertyToSortByNotFoundOnType, typeName…

Error message

SR.Format(SR.PropertyToSortByNotFoundOnType, typeName, sorts[i].PropertyName)

What it means

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.

Solutions

  1. Correct the SortDescription PropertyName to match a public property of the item type exactly (case-insensitive).
  2. Validate property names against the item type (TypeDescriptor.GetProperties(itemType)) before adding sort descriptions.
  3. Only sort on properties present on the base item type declared by the list.
  4. If dynamic sorting is needed, use a typed collection with ListCollectionView instead of BindingListCollectionView.

Example fix

// before
view.SortDescriptions.Add(new SortDescription("Nmae", ListSortDirection.Ascending));

// after
var prop = TypeDescriptor.GetProperties(typeof(Customer)).Find("Name", true);
if (prop != null)
    view.SortDescriptions.Add(new SortDescription("Name", ListSortDirection.Ascending));
Defensive patterns

Strategy: validation

Validate before calling

var props = TypeDescriptor.GetProperties(itemType);
bool exists = props.Find(propertyName, true) != null;
if (!exists) throw new ArgumentException($"Property '{propertyName}' not found on {itemType.Name}");

Type guard

bool propertyExists(Type t, string name) => t.GetProperty(name, BindingFlags.Public | BindingFlags.Instance | BindingFlags.IgnoreCase) != null;

Try / catch

try { view.SortDescriptions.Add(sd); }
catch (ArgumentException ex) { log.Warn($"invalid sort property: {ex.Message}"); }

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Understand the failure class

Background: 'Could not be found', 'does not exist', 'not found in database': the resource-not-found family when an ID, slug, key, or URI lookup comes back empty — this error's family across 20 libraries.

Related errors


AI-assisted analysis of dotnet/wpf@81131a70a4 (2026-09-14). Data as JSON: /api/errors/04589309b657eb77. Report an issue: GitHub.

Appendix: source

Thrown at src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Data/BindingListCollectionView.cs:2204

            {
                pdc = TypeDescriptor.GetProperties(itemType);
            }
            else
            {
                pdc = null;
            }

            if ((pdc == null) || (pdc.Count == 0))
                throw new ArgumentException(SR.CannotDetermineSortByPropertiesForCollection);

            ListSortDescription[] sortDescriptions = new ListSortDescription[sorts.Count];
            for (int i = 0; i < sorts.Count; i++)
            {
                PropertyDescriptor dd = pdc.Find(sorts[i].PropertyName, true);
                if (dd == null)
                {
                    string typeName = itl.GetListName(null);
                    throw new ArgumentException(SR.Format(SR.PropertyToSortByNotFoundOnType, typeName, sorts[i].PropertyName));
                }
                ListSortDescription sd = new ListSortDescription(dd, sorts[i].Direction);
                sortDescriptions[i] = sd;
            }

            return new ListSortDescriptionCollection(sortDescriptions);
        }

        #region Grouping

        // initialization for grouping that should happen before preparing the local array
        private void InitializeGrouping()
        {
            // discard old groups
            _group.Clear();

            // initialize the synthetic top level group
            _group.Initialize();

View on GitHub (pinned to 81131a70a4)