{"record":{"id":"64faa7a73d6a6103","repo":"dotnet/wpf","slug":"sr-format-sr-unexpectedcollectionchangeaction-e-action-64faa7","errorCode":null,"errorMessage":"SR.Format(SR.UnexpectedCollectionChangeAction, e.Action)","messagePattern":"SR\\.Format\\(SR\\.UnexpectedCollectionChangeAction, e\\.Action\\)","errorType":"exception","errorClass":"NotSupportedException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Data/BindingListCollectionView.cs","lineNumber":2457,"sourceCode":"                    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;\n\n                case NotifyCollectionChangedAction.Reset:\n                    break;\n\n                default:\n                    throw new NotSupportedException(SR.Format(SR.UnexpectedCollectionChangeAction, e.Action));\n            }\n        }\n\n        /// <summary>\n        /// Helper to raise a PropertyChanged event  />).\n        /// </summary>\n        private void OnPropertyChanged(string propertyName)\n        {\n            OnPropertyChanged(new PropertyChangedEventArgs(propertyName));\n        }\n\n        #region Deferred work\n\n        // defer work until the current activity completes\n        private void DeferAction(Action action)\n        {\n            if (_deferredActions == null)\n            {","sourceCodeStart":2439,"sourceCodeEnd":2475,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Data/BindingListCollectionView.cs#L2439-L2475","documentation":"The default branch of ValidateCollectionChangedEventArgs throws NotSupportedException for any NotifyCollectionChangedAction value it does not recognize, formatted with UnexpectedCollectionChangeAction. This is a defensive catch-all against corrupt or future/invalid action enums reaching the view.","triggerScenarios":"A source collection raises a CollectionChanged event with an out-of-range or undefined NotifyCollectionChangedAction (e.g. cast from an invalid int, or a hand-constructed event args with a bogus action).","commonSituations":"Custom INotifyCollectionChanged implementations building their own NotifyCollectionChangedEventArgs with an invalid action enum value; unsafe casts of external event data into NotifyCollectionChangedAction; P/Invoke or serialization paths that fabricate change events.","solutions":["Fix the producer of the event to raise only valid NotifyCollectionChangedAction values (Add/Remove/Replace/Move/Reset).","Validate/cast enum values defensively before constructing NotifyCollectionChangedEventArgs.","Update the WPF runtime if a newer NotifyCollectionChangedAction member is the source (unlikely; enum is closed)."],"exampleFix":"// before\nvar args = new NotifyCollectionChangedEventArgs((NotifyCollectionChangedAction)99, item); // throws\n\n// after\nvar args = new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Add, item);","handlingStrategy":"validation","validationCode":"if (!Enum.IsDefined(typeof(NotifyCollectionChangedAction), action))\n    throw new ArgumentOutOfRangeException(nameof(action));","typeGuard":"bool IsValidAction(NotifyCollectionChangedAction a) =>\n    a is NotifyCollectionChangedAction.Add or Remove or Replace or Move or Reset;","tryCatchPattern":"try { ApplyChange(e); } catch (NotSupportedException) { view.Refresh(); }","preventionTips":["Only raise events with defined NotifyCollectionChangedAction values","Validate enum casts from external data before building event args","Never hand-construct event args with raw int actions"],"tags":["wpf","collection-view","invalid-enum-value","not-supported"],"backgroundTag":"invalid-enum-value","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"}