{"record":{"id":"19b6ad5a6eebe555","repo":"dotnet/wpf","slug":"sr-format-sr-cannotfilterview-view","errorCode":null,"errorMessage":"SR.Format(SR.CannotFilterView, view)","messagePattern":"SR\\.Format\\(SR\\.CannotFilterView, view\\)","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Data/CollectionViewSource.cs","lineNumber":1018,"sourceCode":"                    throw new InvalidOperationException(SR.Format(SR.CannotSortView, view));\n\n                // Filter\n                Predicate<object> filter;\n                if (FilterHandlersField.GetValue(this) != null)\n                {\n                    filter = FilterWrapper;\n                }\n                else\n                {\n                    filter = null;\n                }\n\n                if (view.CanFilter)\n                {\n                    view.Filter = filter;\n                }\n                else if (filter != null)\n                    throw new InvalidOperationException(SR.Format(SR.CannotFilterView, view));\n\n                // GroupBy\n                if (view.CanGroup)\n                {\n                    view.GroupDescriptions.Clear();\n                    for (i=0, n=GroupDescriptions.Count;  i < n;  ++i)\n                    {\n                        view.GroupDescriptions.Add(GroupDescriptions[i]);\n                    }\n                }\n                else if (GroupDescriptions.Count > 0)\n                    throw new InvalidOperationException(SR.Format(SR.CannotGroupView, view));\n\n                // Live shaping\n                if (liveView != null)\n                {\n                    ObservableCollection<string> properties;\n","sourceCodeStart":1000,"sourceCodeEnd":1036,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Data/CollectionViewSource.cs#L1000-L1036","documentation":"CollectionViewSource applies its Filter to the generated view only when the view supports filtering (CanFilter). If the view cannot filter but a filter (via FilterHandlersField, i.e. the Filter event/property) is set, it throws InvalidOperationException with CannotFilterView.","triggerScenarios":"Setting cvs.Filter += handler or the Filter property while the resolved view's CanFilter is false, e.g. a custom ICollectionView that doesn't implement filtering over the source collection.","commonSituations":"Custom collection views that skip filtering support; source collections whose default view is not a ListCollectionView; view type overridden via CollectionViewType to a minimal custom implementation.","solutions":["Filter the underlying collection before assigning Source","Make sure the view supports filtering (default views over IList do via ListCollectionView)","Move the predicate into the source data pipeline (e.g. Where in LINQ) instead of the view"],"exampleFix":"// before\ncvs.Filter += (s, e) => e.Accepted = ((Item)e.Item).IsActive; // view.CanFilter == false\n// after\ncvs.Source = items.Where(i => i.IsActive).ToList();","handlingStrategy":"fallback","validationCode":"bool safe = !hasFilterHandler(cvs) || cvs.View?.CanFilter != false; // attach filter only when view can filter","typeGuard":"bool CanApplyFilter(CollectionViewSource cvs) => cvs.View == null || cvs.View.CanFilter;","tryCatchPattern":"try { ActivateView(); } catch (InvalidOperationException ex) when (ex.Message.Contains(\"CannotFilterView\")) { FilterAtSourceInstead(); }","preventionTips":["Check view.CanFilter before wiring the Filter handler","Filter source data with LINQ Where when the view cannot filter","Do not pair custom non-filtering views with Filter handlers"],"tags":["wpf","data-binding","filtering","unsupported-operation"],"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"}