{"record":{"id":"72eb3a4fca70ef61","repo":"dotnet/wpf","slug":"throw-new-invalidoperationexception-sr-format-sr-72eb3a","errorCode":null,"errorMessage":"throw new InvalidOperationException(SR.Format(SR.CannotChangeLiveShaping, \"IsLiveSorting\", \"CanChangeLiveSorting\"));","messagePattern":"throw new InvalidOperationException\\(SR\\.Format\\(SR\\.CannotChangeLiveShaping, \"IsLiveSorting\", \"CanChangeLiveSorting\"\\)\\);","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/Data/CollectionViewProxy.cs","lineNumber":808,"sourceCode":"        /// Gets or sets a value that indicates whether live sorting is enabled.\n        /// The value may be null if the view does not know whether live sorting is enabled.\n        /// Calling the setter when CanChangeLiveSorting is false will throw an\n        /// InvalidOperationException.\n        ///</summary\n        bool? ICollectionViewLiveShaping.IsLiveSorting\n        {\n            get\n            {\n                ICollectionViewLiveShaping cvls = ProxiedView as ICollectionViewLiveShaping;\n                return cvls?.IsLiveSorting;\n            }\n            set\n            {\n                ICollectionViewLiveShaping cvls = ProxiedView as ICollectionViewLiveShaping;\n                if (cvls != null)\n                    cvls.IsLiveSorting = value;\n                else\n                    throw new InvalidOperationException(SR.Format(SR.CannotChangeLiveShaping, \"IsLiveSorting\", \"CanChangeLiveSorting\"));\n            }\n        }\n\n        ///<summary>\n        /// 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            {","sourceCodeStart":790,"sourceCodeEnd":826,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/Data/CollectionViewProxy.cs#L790-L826","documentation":"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.","triggerScenarios":"Assigning proxy.IsLiveSorting = true/false when ProxiedView is not an ICollectionViewLiveShaping (e.g. views that don't support live shaping at all).","commonSituations":"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.","solutions":["Check (ProxiedView as ICollectionViewLiveShaping) != null, or that CanChangeLiveSorting is true, before setting IsLiveSorting","Perform a manual Refresh() of the view instead of live sorting when the view lacks support","Use a view type that implements ICollectionViewLiveShaping (e.g. ListCollectionView on .NET 4.5+)"],"exampleFix":"// before\nproxy.IsLiveSorting = true;\n// after\nif (proxy.ProxiedView is ICollectionViewLiveShaping cvls && cvls.CanChangeLiveSorting)\n{\n    cvls.IsLiveSorting = true;\n}","handlingStrategy":"type-guard","validationCode":"var cvls = proxy.ProxiedView as ICollectionViewLiveShaping;\nif (cvls != null && cvls.CanChangeLiveSorting) { cvls.IsLiveSorting = true; }","typeGuard":"bool SupportsLiveSorting(CollectionViewProxy p) => p?.ProxiedView is ICollectionViewLiveShaping cvls && cvls.CanChangeLiveSorting;","tryCatchPattern":"try { proxy.IsLiveSorting = true; }\ncatch (InvalidOperationException ex) when (ex.Message.Contains(\"IsLiveSorting\")) { proxy.Refresh(); /* manual re-sort instead */ }","preventionTips":["Always check CanChangeLiveSorting before setting IsLiveSorting","Require .NET 4.5+ views (ListCollectionView) for live-shaping features","Fall back to explicit Refresh() when the view cannot do live shaping"],"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"}