dotnet/wpf · error · NotSupportedException

(no message) NotSupportedException

Error message

(no message) NotSupportedException

What it means

ListCollectionView.GroupBySelector is settable only when the view can group (CanGroup). If grouping is not enabled/supported, assigning GroupBySelector throws a bare NotSupportedException before the add/edit-state check is even reached.

Solutions

  1. Ensure grouping is supported and enabled: add a PropertyGroupDescription to view.GroupDescriptions so CanGroup is true
  2. Only set GroupBySelector when view.CanGroup is true
  3. Check whether the underlying IList supports grouping requirements; if not, switch to a collection/view that does

Example fix

// before
view.GroupBySelector = SelectGroup; // NotSupportedException if !CanGroup
// after
if (!view.CanGroup)
    view.GroupDescriptions.Add(new PropertyGroupDescription("Category"));
view.GroupBySelector = SelectGroup;
Defensive patterns

Strategy: validation

Validate before calling

if (!view.CanGroup)
{
    view.GroupDescriptions.Add(new PropertyGroupDescription("Category")); // enable grouping
}
view.GroupBySelector = SelectGroup;

Try / catch

try { view.GroupBySelector = selector; }
catch (NotSupportedException)
{
    // grouping not available for this view; fall back to no grouping
}

Prevention

When it happens

Trigger: Assigning GroupBySelector on a ListCollectionView whose CanGroup is false — typically when SortDescriptions/GroupDescriptions support is unavailable for the underlying list or grouping was never enabled.

Common situations: Attaching grouping logic to a view over a collection that does not support grouping; enabling GroupBySelector in code without first configuring GroupDescriptions; binding a grouping UI control to a non-groupable view.

Related errors


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

Appendix: source

Thrown at src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Data/ListCollectionView.cs:481

                SetSortDescriptions(null);

                RefreshOrDefer();
            }
        }

        /// <summary>
        /// A delegate to select the group description as a function of the
        /// parent group and its level.
        /// </summary>
        [DefaultValue(null)]
        public virtual GroupDescriptionSelectorCallback GroupBySelector
        {
            get { return _group.GroupBySelector; }
            set
            {
                if (!CanGroup)
                    throw new NotSupportedException();
                if (IsAddingNew || IsEditingItem)
                    throw new InvalidOperationException(SR.Format(SR.MemberNotAllowedDuringAddOrEdit, "Grouping"));

                _group.GroupBySelector = value;

                RefreshOrDefer();
            }
        }

        /// <summary>
        /// Return the estimated number of records (or -1, meaning "don't know").
        /// </summary>
        public override int Count
        {
            get
            {
                VerifyRefreshNotDeferred();

View on GitHub (pinned to 81131a70a4)