{"record":{"id":"41a763a82f9b29eb","repo":"dotnet/wpf","slug":"sr-rangeactionsnotsupported-selector","errorCode":null,"errorMessage":"SR.RangeActionsNotSupported","messagePattern":"SR\\.RangeActionsNotSupported","errorType":"exception","errorClass":"NotSupportedException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/Primitives/Selector.cs","lineNumber":873,"sourceCode":"            if (SelectionChange.IsActive)\n            {\n                return;\n            }\n\n            if (!CanSelectMultiple)\n            {\n                throw new InvalidOperationException(SR.ChangingCollectionNotSupported);\n            }\n\n            SelectionChange.Begin();\n            bool succeeded=false;\n            try\n            {\n                switch (e.Action)\n                {\n                    case NotifyCollectionChangedAction.Add:\n                        if (e.NewItems.Count != 1)\n                            throw new NotSupportedException(SR.RangeActionsNotSupported);\n\n                        SelectionChange.Select(NewUnresolvedItemInfo(e.NewItems[0]), false /* assumeInItemsCollection */);\n                        break;\n\n                    case NotifyCollectionChangedAction.Remove:\n                        if (e.OldItems.Count != 1)\n                            throw new NotSupportedException(SR.RangeActionsNotSupported);\n\n                        SelectionChange.Unselect(NewUnresolvedItemInfo(e.OldItems[0]));\n                        break;\n\n                    case NotifyCollectionChangedAction.Reset:\n                        SelectionChange.CleanupDeferSelection();\n                        for (int i = 0; i < _selectedItems.Count; i++)\n                        {\n                            SelectionChange.Unselect(_selectedItems[i]);\n                        }\n","sourceCodeStart":855,"sourceCodeEnd":891,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/Primitives/Selector.cs#L855-L891","documentation":"Selector only supports single-item Add operations on SelectedItems. OnSelectedItemsCollectionChanged throws NotSupportedException when a NotifyCollectionChangedAction.Add event carries more than one new item (a range add), because Selector's SelectionChange logic resolves one item at a time. Range mutations of SelectedItems are explicitly unsupported by the WPF Selector API.","triggerScenarios":"Calling SelectedItems.AddRange or inserting multiple items at once; a custom ObservableCollection<T> derived from SelectedItems' type that fires a bulk Add; any wrapper collection raising Add with NewItems.Count != 1.","commonSituations":"Replacing SelectedItems with a custom collection type that batches changes; bulk-binding code that adds several selected items in one call; framework version differences where bulk Add worked with another collection.","solutions":["Add one item at a time in a loop: foreach (var i in items) listBox.SelectedItems.Add(i);","Replace the whole selection with SelectionMode change plus individual IsSelected=true on each item container","Use ListCollectionView-free plain ListBox APIs: set each ItemContainerStyle binding to IsSelected"],"exampleFix":"// before\nlistBox.SelectedItems.AddRange(newItems); // range add -> throws\n// after\nforeach (var item in newItems)\n    listBox.SelectedItems.Add(item);","handlingStrategy":"validation","validationCode":"if (items.Count > 1)\n    throw new NotSupportedException(\"Selector.SelectedItems supports single-item Add only.\");","typeGuard":null,"tryCatchPattern":"try\n{\n    listBox.SelectedItems.Add(item);\n}\ncatch (NotSupportedException ex)\n{\n    // add items one by one instead\n}","preventionTips":["Never call bulk Add/AddRange on SelectedItems","Loop single Add calls over a snapshot copy","Use IsSelected=true per item for bulk selection"],"tags":["wpf","selector","selecteditems","notsupported"],"backgroundTag":"unsupported-collection-change-action","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"}