dotnet/wpf · error · NotSupportedException
SR.RangeActionsNotSupported
Error message
SR.RangeActionsNotSupported
What it means
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.
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
Example fix
// before
listBox.SelectedItems.AddRange(newItems); // range add -> throws
// after
foreach (var item in newItems)
listBox.SelectedItems.Add(item); Defensive patterns
Strategy: validation
Validate before calling
if (items.Count > 1)
throw new NotSupportedException("Selector.SelectedItems supports single-item Add only."); Try / catch
try
{
listBox.SelectedItems.Add(item);
}
catch (NotSupportedException ex)
{
// add items one by one instead
} Prevention
- Never call bulk Add/AddRange on SelectedItems
- Loop single Add calls over a snapshot copy
- Use IsSelected=true per item for bulk selection
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- SR.UnexpectedCollectionChangeAction
- new NotSupportedException()
- NotSupportedException
- SR.CannotSelectNotSelectableItem
- SR.ChangingCollectionNotSupported
AI-assisted analysis of dotnet/wpf@81131a70a4 (2026-09-14).
Data as JSON: /api/errors/41a763a82f9b29eb.
Report an issue: GitHub.
Appendix: source
Thrown at src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/Primitives/Selector.cs:873
if (SelectionChange.IsActive)
{
return;
}
if (!CanSelectMultiple)
{
throw new InvalidOperationException(SR.ChangingCollectionNotSupported);
}
SelectionChange.Begin();
bool succeeded=false;
try
{
switch (e.Action)
{
case NotifyCollectionChangedAction.Add:
if (e.NewItems.Count != 1)
throw new NotSupportedException(SR.RangeActionsNotSupported);
SelectionChange.Select(NewUnresolvedItemInfo(e.NewItems[0]), false /* assumeInItemsCollection */);
break;
case NotifyCollectionChangedAction.Remove:
if (e.OldItems.Count != 1)
throw new NotSupportedException(SR.RangeActionsNotSupported);
SelectionChange.Unselect(NewUnresolvedItemInfo(e.OldItems[0]));
break;
case NotifyCollectionChangedAction.Reset:
SelectionChange.CleanupDeferSelection();
for (int i = 0; i < _selectedItems.Count; i++)
{
SelectionChange.Unselect(_selectedItems[i]);
}
View on GitHub (pinned to 81131a70a4)