{"record":{"id":"dc6dd1f0b124f76a","repo":"dotnet/wpf","slug":"sr-rangeactionsnotsupported-bindinglistcollectionview","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/Data/BindingListCollectionView.cs","lineNumber":2433,"sourceCode":"                }\n            }\n        }\n\n        private void OnLiveShapingDirty(object sender, EventArgs e)\n        {\n            IsLiveShapingDirty = true;\n        }\n\n        #endregion Live Shaping\n\n\n        private void ValidateCollectionChangedEventArgs(NotifyCollectionChangedEventArgs e)\n        {\n            switch (e.Action)\n            {\n                case NotifyCollectionChangedAction.Add:\n                    if (e.NewItems.Count != 1)\n                        throw new NotSupportedException(SR.RangeActionsNotSupported);\n                    break;\n\n                case NotifyCollectionChangedAction.Remove:\n                    if (e.OldItems.Count != 1)\n                        throw new NotSupportedException(SR.RangeActionsNotSupported);\n                    break;\n\n                case NotifyCollectionChangedAction.Replace:\n                    if (e.NewItems.Count != 1 || e.OldItems.Count != 1)\n                        throw new NotSupportedException(SR.RangeActionsNotSupported);\n                    break;\n\n                case NotifyCollectionChangedAction.Move:\n                    if (e.NewItems.Count != 1)\n                        throw new NotSupportedException(SR.RangeActionsNotSupported);\n                    if (e.NewStartingIndex < 0)\n                        throw new InvalidOperationException(SR.CannotMoveToUnknownPosition);\n                    break;","sourceCodeStart":2415,"sourceCodeEnd":2451,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Data/BindingListCollectionView.cs#L2415-L2451","documentation":"BindingListCollectionView.ValidateCollectionChangedEventArgs rejects any NotifyCollectionChangedAction.Add whose NewItems contains more than one element with NotSupportedException(SR.RangeActionsNotSupported). The view only supports single-item collection change notifications and does not implement range processing.","triggerScenarios":"The underlying IBindingList or collection raises a ListChanged/CollectionChanged Add event with a batch of items (multi-element NewItems), e.g. calling AddRange on an ObservableCollection-derived type that raises one multi-item Add notification.","commonSituations":"Bulk-loading data into a bound ObservableCollection via a custom AddRange that packs all items into one ChangeNotification; third-party collection libraries that emit multi-item Add events consumed by a BindingListCollectionView-backed view.","solutions":["Add items one at a time so each notification carries exactly one NewItems element.","Wrap multi-item inserts: suspend the view's refresh, raise Reset instead of a range Add, then Refresh the view.","Change the source to raise NotifyCollectionChangedAction.Reset for bulk changes (clear + repopulate) rather than a multi-item Add."],"exampleFix":"// before\nvoid AddRange(IEnumerable<T> items) {\n    foreach (var i in items) _inner.Add(i);\n    OnCollectionChanged(new NotifyCollectionChangedEventArgs(Add, items.ToList())); // throws in view\n}\n\n// after\nvoid AddRange(IEnumerable<T> items) {\n    foreach (var i in items) _inner.Add(i); // per-item Add notifications, count == 1\n}","handlingStrategy":"type-guard","validationCode":"if (e.Action == NotifyCollectionChangedAction.Add && e.NewItems.Count > 1)\n{\n    // republish as Reset or per-item Adds instead of a range Add\n}","typeGuard":"bool IsSingleItemAdd(NotifyCollectionChangedEventArgs e) =>\n    e.Action != NotifyCollectionChangedAction.Add || (e.NewItems?.Count ?? 0) == 1;","tryCatchPattern":"try { view.Refresh(); } catch (NotSupportedException) { /* fall back to Reset+Refresh for bulk changes */ }","preventionTips":["Never raise multi-item Add notifications toward a BindingListCollectionView","Use Reset notifications for bulk inserts plus CollectionView.Refresh","Audit custom AddRange implementations for batched events"],"tags":["wpf","collection-view","not-supported","range-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-22T01:17:13.364Z"}