dotnet/wpf · error · InvalidOperationException

throw new…

Error message

throw new InvalidOperationException(SR.Format(SR.CannotChangeLiveShaping, "IsLiveGrouping", "CanChangeLiveGrouping"));

What it means

CollectionViewProxy throws this when the IsLiveGrouping setter is called but the proxied view does not implement ICollectionViewLiveShaping (or does not report CanChangeLiveGrouping). WPF raises it to signal that live shaping cannot be changed on this view, so the property assignment fails immediately with an InvalidOperationException rather than silently doing nothing.

Solutions

  1. Check CanChangeLiveGrouping (or cast the view to ICollectionViewLiveShaping) before setting IsLiveGrouping.
  2. Only enable live grouping on views known to support it, e.g. ListCollectionView over a collection whose items implement ILiveShaping properties.
  3. If the source collection must support live shaping, back it with a ListCollectionView instead of a proxy over a non-shaping view.

Example fix

// before
viewProxy.IsLiveGrouping = true;

// after
if (viewProxy is ICollectionViewLiveShaping cvls && cvls.CanChangeLiveGrouping)
{
    cvls.IsLiveGrouping = true;
}
Defensive patterns

Strategy: validation

Validate before calling

if (viewProxy is ICollectionViewLiveShaping cvls && cvls.CanChangeLiveGrouping)
    viewProxy.IsLiveGrouping = value;

Type guard

bool supportsLiveShaping = view.ProxiedView is ICollectionViewLiveShaping;

Prevention

When it happens

Trigger: Setting the IsLiveGrouping property on a CollectionViewProxy whose ProxiedView is not an ICollectionViewLiveShaping (e.g. a plain CollectionView or custom ICollectionView without live shaping support).

Common situations: Binding IsLiveGrouping in XAML or code on a view that does not support live grouping (e.g. a CompositeCollectionView-backed or custom view); applying live-shaping settings uniformly across heterogeneous collection views where some views lack the feature.

Understand the failure class

Background: "Invalid state transition" errors: "status must be X, actually Y", "already rejected/charging/uninstalled", "cannot ... while running" — what they mean when a library rejects your call — this error's family across 31 libraries.

Related errors


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

Appendix: source

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

        /// 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
            {
                ICollectionViewLiveShaping cvls = ProxiedView as ICollectionViewLiveShaping;
                if (cvls != null)
                    cvls.IsLiveGrouping = value;
                else
                    throw new InvalidOperationException(SR.Format(SR.CannotChangeLiveShaping, "IsLiveGrouping", "CanChangeLiveGrouping"));
            }
        }


        ///<summary>
        /// Gets a collection of strings describing the properties that
        /// trigger a live-sorting recalculation.
        /// The strings use the same format as SortDescription.PropertyName.
        ///</summary>
        ///<notes>
        /// When this collection is empty, the view will use the PropertyName strings
        /// from its SortDescriptions.
        ///
        /// This collection is useful when sorting is described code supplied
        /// by the application  (e.g. ListCollectionView.CustomSort).
        /// In this case the view does not know which properties the code examines;
        /// the application should tell the view by adding the relevant properties
        /// to the LiveSortingProperties collection.

View on GitHub (pinned to 81131a70a4)