dotnet/wpf · error · InvalidOperationException

throw new…

Error message

throw new InvalidOperationException(SR.Format(SR.CannotChangeLiveShaping, "IsLiveSorting", "CanChangeLiveSorting"));

What it means

The IsLiveSorting setter on CollectionViewProxy requires the proxied view to implement ICollectionViewLiveShaping. If it does not (failed cast at CollectionViewProxy.cs:808), the setter throws InvalidOperationException with SR.CannotChangeLiveShaping, telling you live sorting cannot be changed on a view whose CanChangeLiveSorting is not satisfied.

Solutions

  1. Check (ProxiedView as ICollectionViewLiveShaping) != null, or that CanChangeLiveSorting is true, before setting IsLiveSorting
  2. Perform a manual Refresh() of the view instead of live sorting when the view lacks support
  3. Use a view type that implements ICollectionViewLiveShaping (e.g. ListCollectionView on .NET 4.5+)

Example fix

// before
proxy.IsLiveSorting = true;
// after
if (proxy.ProxiedView is ICollectionViewLiveShaping cvls && cvls.CanChangeLiveSorting)
{
    cvls.IsLiveSorting = true;
}
Defensive patterns

Strategy: type-guard

Validate before calling

var cvls = proxy.ProxiedView as ICollectionViewLiveShaping;
if (cvls != null && cvls.CanChangeLiveSorting) { cvls.IsLiveSorting = true; }

Type guard

bool SupportsLiveSorting(CollectionViewProxy p) => p?.ProxiedView is ICollectionViewLiveShaping cvls && cvls.CanChangeLiveSorting;

Try / catch

try { proxy.IsLiveSorting = true; }
catch (InvalidOperationException ex) when (ex.Message.Contains("IsLiveSorting")) { proxy.Refresh(); /* manual re-sort instead */ }

Prevention

When it happens

Trigger: Assigning proxy.IsLiveSorting = true/false when ProxiedView is not an ICollectionViewLiveShaping (e.g. views that don't support live shaping at all).

Common situations: Enabling live sorting on collections bound to views without live-shaping support; copying live-shaping settings across different collection view types; older custom views predating .NET 4.5's ICollectionViewLiveShaping.

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/72eb3a4fca70ef61. Report an issue: GitHub.

Appendix: source

Thrown at src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/Data/CollectionViewProxy.cs:808

        /// 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
        bool? ICollectionViewLiveShaping.IsLiveSorting
        {
            get
            {
                ICollectionViewLiveShaping cvls = ProxiedView as ICollectionViewLiveShaping;
                return cvls?.IsLiveSorting;
            }
            set
            {
                ICollectionViewLiveShaping cvls = ProxiedView as ICollectionViewLiveShaping;
                if (cvls != null)
                    cvls.IsLiveSorting = value;
                else
                    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>
        bool? ICollectionViewLiveShaping.IsLiveFiltering
        {
            get
            {
                ICollectionViewLiveShaping cvls = ProxiedView as ICollectionViewLiveShaping;
                return cvls?.IsLiveFiltering;
            }
            set
            {

View on GitHub (pinned to 81131a70a4)