{"record":{"id":"7e65b8b12c516c99","repo":"dotnet/wpf","slug":"sr-rangeactionsnotsupported-collectionview","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/CollectionView.cs","lineNumber":1952,"sourceCode":"\n            // if changes remain (because we ran out of time), reschedule them\n            if (unprocessedChanges != null && unprocessedChanges.Count > 0)\n            {\n                DeferProcessing(unprocessedChanges);\n            }\n\n            _tempChangeLog = s_emptyList;\n\n            return null;\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                    if (e.OldStartingIndex < 0)\n                        throw new InvalidOperationException(SR.RemovedItemNotFound);\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)","sourceCodeStart":1934,"sourceCodeEnd":1970,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Data/CollectionView.cs#L1934-L1970","documentation":"CollectionView only supports single-item change notifications. ValidateCollectionChangedEventArgs throws NotSupportedException for Add events whose NewItems contains more than one item (range Add). Underlying collections must raise separate single-item notifications for the view to process them.","triggerScenarios":"Raising CollectionChanged with NotifyCollectionChangedAction.Add and a NewItems list of count > 1 (or null) from a custom INotifyCollectionChanged collection consumed by a CollectionView.","commonSituations":"Custom observable collections implementing bulk AddRange with a single multi-item Add event; third-party collections that batch notifications; ports of collections that assumed range actions were allowed.","solutions":["Raise one single-item Add event per element in AddRange (optionally wrapped in DeferRefresh on the view)","Change the notification action to Reset for bulk changes","Use a collection library whose bulk operations are WPF-compatible (e.g. raising Reset or per-item events)"],"exampleFix":"// before\nOnCollectionChanged(new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Add, newItems)); // range\n// after\nforeach (var item in newItems)\n    OnCollectionChanged(new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Add, item));","handlingStrategy":"validation","validationCode":"if (e.Action == NotifyCollectionChangedAction.Add && (e.NewItems == null || e.NewItems.Count > 1))\n    throw new ArgumentException(\"CollectionView requires single-item Add notifications.\");","typeGuard":"bool isSingleAdd(NotifyCollectionChangedEventArgs e) => e.Action != NotifyCollectionChangedAction.Add || e.NewItems?.Count == 1;","tryCatchPattern":"try { OnCollectionChanged(e); }\ncatch (NotSupportedException) { foreach (var i in e.NewItems) RaiseSingleAdd(i); }","preventionTips":["Custom INotifyCollectionChanged collections must raise one item per Add event","Use Reset for bulk changes","Test custom collections against a CollectionView before shipping"],"tags":["wpf","collectionview","inotifycollectionchanged","range-operations"],"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"}