{"record":{"id":"5188d547740eee97","repo":"dotnet/wpf","slug":"sr-format-sr-unexpectedcollectionchangeaction-e-action-5188d5","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/ListCollectionView.cs","lineNumber":2411,"sourceCode":"                    {\n                        // allow the ShadowCollection to throw the IndexOutOfRangeException\n                        // if the item is not found.\n                        tempIndex = ShadowCollection.IndexOf(e.OldItems[0]);\n                        ShadowCollection[tempIndex] = e.NewItems[0];\n                    }\n                    break;\n                case NotifyCollectionChangedAction.Move:\n                    tempIndex = e.OldStartingIndex;\n                    if (tempIndex < 0)\n                    {\n                        tempIndex = ShadowCollection.IndexOf(e.NewItems[0]);\n                    }\n                    ShadowCollection.RemoveAt(tempIndex);\n                    ShadowCollection.Insert(e.NewStartingIndex, e.NewItems[0]);\n                    break;\n\n                default:\n                    throw new NotSupportedException(SR.Format(SR.UnexpectedCollectionChangeAction, e.Action));\n            }\n        }\n\n        // returns true if this ListCollectionView has sort descriptions,\n        // without tripping off lazy creation of .SortDescriptions collection\n        internal bool HasSortDescriptions\n        {\n            get { return ((_sort != null) && (_sort.Count > 0)); }\n        }\n\n        // return an appropriate comparer.   Common logic used by ListCollectionView\n        // and by CollectionViewGroupInternal.\n        internal static IComparer PrepareComparer(IComparer customSort, SortDescriptionCollection sort, Func<object, CollectionView> lazyGetCollectionView, object state)\n        {\n            if (customSort != null)\n            {\n                return customSort;\n            }","sourceCodeStart":2393,"sourceCodeEnd":2429,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Data/ListCollectionView.cs#L2393-L2429","documentation":"ListCollectionView.ProcessCollectionChange encountered a NotifyCollectionChangedAction value outside Add/Remove/Replace/Move/Reset when replaying an underlying-collection change into its shadow copy. Since .NET has no other defined actions, this indicates a corrupt or custom-injected event argument. It is thrown as NotSupportedException to signal the view cannot process the change.","triggerScenarios":"A CollectionChanged handler path in ProcessCollectionChange receives e.Action not equal to Add, Remove, Replace, Move, or Reset — practically only from a custom INotifyCollectionChanged implementation passing an invalid/cast enum value.","commonSituations":"Custom observable collections that manually raise CollectionChanged with hand-crafted or unvalidated NotifyCollectionChangedEventArgs; aggressive enum casts like (NotifyCollectionChangedAction)99; interop code reusing event args across libraries.","solutions":["Fix the custom INotifyCollectionChanged source to only raise the five standard NotifyCollectionChangedAction values.","Construct event args via NotifyCollectionChangedEventArgs.Add/Remove/Replace/Move/Reset factories instead of custom subclasses.","Catch NotSupportedException around collection mutations if the event source is out of your control, and resync the view by calling Refresh()."],"exampleFix":"// before (custom collection)\nOnCollectionChanged(new NotifyCollectionChangedEventArgs((NotifyCollectionChangedAction)99));\n// after\nOnCollectionChanged(new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Reset));","handlingStrategy":"type-guard","validationCode":"if (!Enum.IsDefined(typeof(NotifyCollectionChangedAction), args.Action)) throw new InvalidOperationException(\"Invalid collection change action\");","typeGuard":"bool IsValidAction(NotifyCollectionChangedAction a) => a is NotifyCollectionChangedAction.Add or NotifyCollectionChangedAction.Remove or NotifyCollectionChangedAction.Replace or NotifyCollectionChangedAction.Move or NotifyCollectionChangedAction.Reset;","tryCatchPattern":"try { view.Refresh(); } catch (NotSupportedException) { view.Refresh(); /* resync view from source */ }","preventionTips":["Only raise the five standard NotifyCollectionChangedAction values","Use NotifyCollectionChangedEventArgs static factory methods","Never cast arbitrary ints to NotifyCollectionChangedAction without Enum.IsDefined"],"tags":["wpf","collection-view","not-supported"],"backgroundTag":"unsupported-operation","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"}