{"record":{"id":"62a7f140b1d83458","repo":"dotnet/wpf","slug":"sr-unexpectedcollectionchangeaction","errorCode":null,"errorMessage":"SR.UnexpectedCollectionChangeAction","messagePattern":"SR\\.UnexpectedCollectionChangeAction","errorType":"exception","errorClass":"NotSupportedException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/Primitives/Selector.cs","lineNumber":912,"sourceCode":"                        for (int i = 0; i < userSelectedItems.Count; i++)\n                        {\n                            SelectionChange.Select(NewUnresolvedItemInfo(userSelectedItems[i]), false /* assumeInItemsCollection */);\n                        }\n                        break;\n\n                    case NotifyCollectionChangedAction.Replace:\n                        if (e.NewItems.Count != 1 || e.OldItems.Count != 1)\n                            throw new NotSupportedException(SR.RangeActionsNotSupported);\n\n                        SelectionChange.Unselect(NewUnresolvedItemInfo(e.OldItems[0]));\n                        SelectionChange.Select(NewUnresolvedItemInfo(e.NewItems[0]), false /* assumeInItemsCollection */);\n                        break;\n\n                    case NotifyCollectionChangedAction.Move:\n                        break;  // order within SelectedItems doesn't matter\n\n                    default:\n                        throw new NotSupportedException(SR.Format(SR.UnexpectedCollectionChangeAction, e.Action));\n                }\n\n                SelectionChange.End();\n                succeeded = true;\n            }\n            finally\n            {\n                if (!succeeded)\n                {\n                    SelectionChange.Cancel();\n                }\n            }\n        }\n\n        #endregion\n\n\n        //-------------------------------------------------------------------","sourceCodeStart":894,"sourceCodeEnd":930,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/Primitives/Selector.cs#L894-L930","documentation":"OnSelectedItemsCollectionChanged handles only Add, Remove, Reset, Replace and Move events on SelectedItems; any other NotifyCollectionChangedAction reaches the default case and throws NotSupportedException with UnexpectedCollectionChangeAction. In practice this fires when a custom INotifyCollectionChanged implementation raises a nonstandard or unexpected action against SelectedItems.","triggerScenarios":"Assigning a custom collection to SelectedItems whose RaiseCollectionChanged uses a nonstandard action value; wrappers or AOP proxies that synthesize events with invalid actions; a subclass of ObservableCollection overriding collection-change propagation with custom actions.","commonSituations":"Advanced MVVM frameworks swapping the internal SelectedItems collection; code generation or interception frameworks mis-raising collection-change events; porting code that relied on nonstandard actions in other collection implementations.","solutions":["Only assign collections whose change notifications use the standard NotifyCollectionChangedAction values (Add/Remove/Reset/Replace/Move)","Do not replace the built-in SelectedItems collection; instead drive selection via item IsSelected or SelectedItem","If a custom collection is required, raise Reset for any bulk or unusual change"],"exampleFix":"// before\ncustomCollection.RaiseAction((NotifyCollectionChangedAction)99, items); // invalid action\n// after\ncustomCollection.OnCollectionChanged(new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Reset));","handlingStrategy":"validation","validationCode":"if (!Enum.IsDefined(typeof(NotifyCollectionChangedAction), action))\n    throw new NotSupportedException(\"Unsupported collection change action.\");","typeGuard":null,"tryCatchPattern":"try\n{\n    UpdateSelection(e);\n}\ncatch (NotSupportedException ex)\n{\n    // log and resync selection from SelectedItems\n}","preventionTips":["Only use standard NotifyCollectionChangedAction values","Raise Reset for custom or bulk changes","Don't replace Selector's internal SelectedItems collection"],"tags":["wpf","selector","collectionchanged","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"}