dotnet/wpf · error · InvalidOperationException

throw new…

Error message

throw new InvalidOperationException(SR.Format(SR.CannotChangeLiveShaping, "IsLiveFiltering", "CanChangeLiveFiltering"));

What it means

The IsLiveFiltering setter on CollectionViewProxy forwards to the proxied view's ICollectionViewLiveShaping.IsLiveFiltering. If the wrapped view does not implement ICollectionViewLiveShaping (failed cast at CollectionViewProxy.cs:831), the setter throws InvalidOperationException (SR.CannotChangeLiveShaping) because live filtering cannot be changed on this view.

Solutions

  1. Verify ProxiedView is ICollectionViewLiveShaping and CanChangeLiveFiltering before setting IsLiveFiltering
  2. Fall back to setting the static Filter property and calling Refresh() when live filtering is unsupported
  3. Bind to a view type implementing ICollectionViewLiveShaping (ListCollectionView on .NET 4.5+)

Example fix

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

Strategy: type-guard

Validate before calling

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

Type guard

bool SupportsLiveFiltering(CollectionViewProxy p) => p?.ProxiedView is ICollectionViewLiveShaping cvls && cvls.CanChangeLiveFiltering;

Try / catch

try { proxy.IsLiveFiltering = true; }
catch (InvalidOperationException ex) when (ex.Message.Contains("IsLiveFiltering")) { proxy.Filter = myPredicate; proxy.Refresh(); }

Prevention

When it happens

Trigger: Assigning proxy.IsLiveFiltering = true/false when ProxiedView lacks ICollectionViewLiveShaping support.

Common situations: Toggling live filtering on views that only support static Filter; settings panels that unconditionally flip live-shaping flags; custom collection views without the live-shaping interface.

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/4a4eaf97cd4c507b. Report an issue: GitHub.

Appendix: source

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

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

View on GitHub (pinned to 81131a70a4)