{"record":{"id":"4a4eaf97cd4c507b","repo":"dotnet/wpf","slug":"throw-new-invalidoperationexception-sr-format-sr-4a4eaf","errorCode":null,"errorMessage":"throw new InvalidOperationException(SR.Format(SR.CannotChangeLiveShaping, \"IsLiveFiltering\", \"CanChangeLiveFiltering\"));","messagePattern":"throw new InvalidOperationException\\(SR\\.Format\\(SR\\.CannotChangeLiveShaping, \"IsLiveFiltering\", \"CanChangeLiveFiltering\"\\)\\);","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/Data/CollectionViewProxy.cs","lineNumber":831,"sourceCode":"        /// Gets or sets a value that indicates whether live filtering is enabled.\n        /// The value may be null if the view does not know whether live filtering is enabled.\n        /// Calling the setter when CanChangeLiveFiltering is false will throw an\n        /// InvalidOperationException.\n        ///</summary>\n        bool? ICollectionViewLiveShaping.IsLiveFiltering\n        {\n            get\n            {\n                ICollectionViewLiveShaping cvls = ProxiedView as ICollectionViewLiveShaping;\n                return cvls?.IsLiveFiltering;\n            }\n            set\n            {\n                ICollectionViewLiveShaping cvls = ProxiedView as ICollectionViewLiveShaping;\n                if (cvls != null)\n                    cvls.IsLiveFiltering = value;\n                else\n                    throw new InvalidOperationException(SR.Format(SR.CannotChangeLiveShaping, \"IsLiveFiltering\", \"CanChangeLiveFiltering\"));\n            }\n        }\n\n        ///<summary>\n        /// Gets or sets a value that indicates whether live grouping is enabled.\n        /// The value may be null if the view does not know whether live grouping is enabled.\n        /// Calling the setter when CanChangeLiveGrouping is false will throw an\n        /// InvalidOperationException.\n        ///</summary>\n        bool? ICollectionViewLiveShaping.IsLiveGrouping\n        {\n            get\n            {\n                ICollectionViewLiveShaping cvls = ProxiedView as ICollectionViewLiveShaping;\n                return cvls?.IsLiveGrouping;\n            }\n            set\n            {","sourceCodeStart":813,"sourceCodeEnd":849,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/Data/CollectionViewProxy.cs#L813-L849","documentation":"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.","triggerScenarios":"Assigning proxy.IsLiveFiltering = true/false when ProxiedView lacks ICollectionViewLiveShaping support.","commonSituations":"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.","solutions":["Verify ProxiedView is ICollectionViewLiveShaping and CanChangeLiveFiltering before setting IsLiveFiltering","Fall back to setting the static Filter property and calling Refresh() when live filtering is unsupported","Bind to a view type implementing ICollectionViewLiveShaping (ListCollectionView on .NET 4.5+)"],"exampleFix":"// before\nproxy.IsLiveFiltering = true;\n// after\nif (proxy.ProxiedView is ICollectionViewLiveShaping cvls && cvls.CanChangeLiveFiltering)\n{\n    cvls.IsLiveFiltering = true;\n}","handlingStrategy":"type-guard","validationCode":"var cvls = proxy.ProxiedView as ICollectionViewLiveShaping;\nif (cvls != null && cvls.CanChangeLiveFiltering) { cvls.IsLiveFiltering = true; }","typeGuard":"bool SupportsLiveFiltering(CollectionViewProxy p) => p?.ProxiedView is ICollectionViewLiveShaping cvls && cvls.CanChangeLiveFiltering;","tryCatchPattern":"try { proxy.IsLiveFiltering = true; }\ncatch (InvalidOperationException ex) when (ex.Message.Contains(\"IsLiveFiltering\")) { proxy.Filter = myPredicate; proxy.Refresh(); }","preventionTips":["Check CanChangeLiveFiltering before toggling IsLiveFiltering","Use static Filter + Refresh() as a fallback on views without live shaping","Centralize live-shaping feature detection in a helper for all shaping flags (sorting, filtering, grouping)"],"tags":["wpf","collection-view","live-shaping","invalidoperation"],"backgroundTag":"unsupported-operation","analyzedSha":"81131a70a4c573cd62748a5c36908fc4d662daa9","analyzedAt":"2026-09-14T10:12:48.479Z","contentChangedAt":"2026-09-14T10:12:48.479Z","schemaVersion":2},"datasetVersion":"2026-09-21T21:30:21.729Z"}