{"record":{"id":"e7bf8b84f5158203","repo":"dotnet/wpf","slug":"sr-format-sr-cannotgroupview-view","errorCode":null,"errorMessage":"SR.Format(SR.CannotGroupView, view)","messagePattern":"SR\\.Format\\(SR\\.CannotGroupView, view\\)","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Data/CollectionViewSource.cs","lineNumber":1030,"sourceCode":"\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\n                    // sorting\n                    if (liveView.CanChangeLiveSorting)\n                    {\n                        liveView.IsLiveSorting = IsLiveSortingRequested;\n                        properties = liveView.LiveSortingProperties;\n                        properties.Clear();\n\n                        if (IsLiveSortingRequested)\n                        {\n                            foreach (string s in LiveSortingProperties)\n                            {\n                                properties.Add(s);","sourceCodeStart":1012,"sourceCodeEnd":1048,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Data/CollectionViewSource.cs#L1012-L1048","documentation":"CollectionViewSource copies its GroupDescriptions onto the generated view only if the view supports grouping (CanGroup). If the view cannot group but GroupDescriptions contains entries, it throws InvalidOperationException with CannotGroupView.","triggerScenarios":"Adding GroupDescriptions (e.g. PropertyGroupDescription) to a CollectionViewSource whose generated view reports CanGroup == false, such as a custom or minimal ICollectionView implementation.","commonSituations":"Grouping a bound collection whose view type doesn't implement ICollectionView grouping; overriding CollectionViewType to a custom non-grouping view while XAML defines group descriptions.","solutions":["Group the data at the source (e.g. GroupBy in LINQ with CollectionViewSource over grouped structures) or use a view that supports grouping","Ensure the default ListCollectionView is generated (bind to IList-backed collections)","Remove GroupDescriptions when the target view cannot group"],"exampleFix":"// before\ncvs.GroupDescriptions.Add(new PropertyGroupDescription(\"Category\")); // view.CanGroup == false\n// after\ncvs.Source = items.GroupBy(i => i.Category).Select(g => new { Category = g.Key, Items = g.ToList() }).ToList();","handlingStrategy":"fallback","validationCode":"bool safe = !cvs.GroupDescriptions.Any() || cvs.View?.CanGroup == true;","typeGuard":"bool CanApplyGrouping(CollectionViewSource cvs) => cvs.View == null || cvs.View.CanGroup || !cvs.GroupDescriptions.Any();","tryCatchPattern":"try { ActivateView(); } catch (InvalidOperationException ex) when (ex.Message.Contains(\"CannotGroupView\")) { GroupAtSourceInstead(); }","preventionTips":["Check view.CanGroup before adding GroupDescriptions","Group at the source with LINQ GroupBy for non-grouping views","Keep default ListCollectionView when XAML grouping is used"],"tags":["wpf","data-binding","grouping","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"}