dotnet/wpf · error · InvalidOperationException

SR.Format(SR.CannotChangeLiveShaping, "IsLiveSorting"…

Error message

SR.Format(SR.CannotChangeLiveShaping, "IsLiveSorting", "CanChangeLiveSorting")

What it means

BindingListCollectionView exposes IsLiveSorting only as a read-only indicator (true when the underlying collection is an IBindingListView/DataView, null otherwise). Its setter unconditionally throws InvalidOperationException because BindingListCollectionView cannot change live sorting; live shaping can only be toggled on views where CanChangeLiveSorting is true (e.g. ListCollectionView).

Solutions

  1. Do not set IsLiveSorting on BindingListCollectionView; read it to check whether live sorting is active.
  2. If live shaping toggling is required, use a ListCollectionView (e.g. over an ObservableCollection) where CanChangeLiveSorting is true.
  3. Wrap the set in a check: only assign when the view is a ListCollectionView and CanChangeLiveSorting is true.
  4. For DataView-backed sources, control live sorting through the underlying DataView / binding list instead of the view.

Example fix

// before
((BindingListCollectionView)CollectionViewSource.GetDefaultView(dataTable)).IsLiveSorting = true;

// after
var view = CollectionViewSource.GetDefaultView(dataTable); // read-only indicator
bool liveSortingActive = (view as BindingListCollectionView)?.IsLiveSorting == true;
Defensive patterns

Strategy: validation

Validate before calling

if (view is BindingListCollectionView)
    throw new NotSupportedException("IsLiveSorting cannot be set on BindingListCollectionView");

Type guard

bool canSetLiveSorting(CollectionView v) => v is ListCollectionView lcv && lcv.CanChangeLiveSorting;

Try / catch

try { view.IsLiveSorting = true; }
catch (InvalidOperationException) { /* view is read-only for live shaping */ }

Prevention

When it happens

Trigger: Setting the IsLiveSorting property on a BindingListCollectionView instance (e.g. ((BindingListCollectionView)CollectionViewSource.GetDefaultView(dataTable)).IsLiveSorting = true;). The throw is unconditional — it does not depend on the value assigned.

Common situations: XAML or code that sets IsLiveSorting on the default view of an ADO.NET DataTable/DataView or any IBindingListView-backed source, often code copied from examples written for ListCollectionView or ObservableCollection views.

Understand the failure class

Background: UnsupportedOperationException and "is not supported" errors: when a library deliberately refuses a call — this error's family across 30 libraries.

Related errors


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

Appendix: source

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

        { get { return false; } }

        ///<summary>
        /// Gets a value that indicates whether this view supports turning live grouping on or off.
        ///</summary>
        public bool CanChangeLiveGrouping
        { get { return true; } }


        ///<summary>
        /// Gets or sets a value that indicates whether live sorting is enabled.
        /// The value may be null if the view does not know whether live sorting is enabled.
        /// Calling the setter when CanChangeLiveSorting is false will throw an
        /// InvalidOperationException.
        ///</summary
        public bool? IsLiveSorting
        {
            get { return IsDataView ? (bool?)true : (bool?)null; }
            set { throw new InvalidOperationException(SR.Format(SR.CannotChangeLiveShaping, "IsLiveSorting", "CanChangeLiveSorting")); }
        }

        ///<summary>
        /// Gets or sets a value that indicates whether live filtering is enabled.
        /// The value may be null if the view does not know whether live filtering is enabled.
        /// Calling the setter when CanChangeLiveFiltering is false will throw an
        /// InvalidOperationException.
        ///</summary>
        public bool? IsLiveFiltering
        {
            get { return IsDataView ? (bool?)true : (bool?)null; }
            set { throw new InvalidOperationException(SR.Format(SR.CannotChangeLiveShaping, "IsLiveFiltering", "CanChangeLiveFiltering")); }
        }

        ///<summary>
        /// Gets or sets a value that indicates whether live grouping is enabled.
        /// The value may be null if the view does not know whether live grouping is enabled.
        /// Calling the setter when CanChangeLiveGrouping is false will throw an

View on GitHub (pinned to 81131a70a4)