{"record":{"id":"e88028071ce938e4","repo":"dotnet/wpf","slug":"sr-freezable-unexpectedchange","errorCode":null,"errorMessage":"SR.Freezable_UnexpectedChange","messagePattern":"SR\\.Freezable_UnexpectedChange","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/FreezableCollection.cs","lineNumber":754,"sourceCode":"                {\n                    NotifyCollectionChangedEventArgs args;\n\n                    switch (action)\n                    {\n                        case NotifyCollectionChangedAction.Reset:\n                            args = new NotifyCollectionChangedEventArgs(action);\n                            break;\n                        case NotifyCollectionChangedAction.Add:\n                            args = new NotifyCollectionChangedEventArgs(action, newValue, newIndex);\n                            break;\n                        case NotifyCollectionChangedAction.Remove:\n                            args = new NotifyCollectionChangedEventArgs(action, oldValue, oldIndex);\n                            break;\n                        case NotifyCollectionChangedAction.Replace:\n                            args = new NotifyCollectionChangedEventArgs(action, newValue, oldValue, newIndex);\n                            break;\n                        default:\n                            throw new InvalidOperationException(SR.Freezable_UnexpectedChange);\n                    }\n\n                    OnCollectionChanged(args);\n                }\n            }\n        }\n\n\n        #endregion Private Helpers\n\n        //------------------------------------------------------\n        //\n        //  Protected Methods\n        //\n        //------------------------------------------------------\n\n        #region Protected Methods\n","sourceCodeStart":736,"sourceCodeEnd":772,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/FreezableCollection.cs#L736-L772","documentation":"OnCollectionChanged raises InvalidOperationException(SR.Freezable_UnexpectedChange) when it receives a NotifyCollectionChangedAction other than Add, Remove, Replace, Move, or Reset (i.e. the default/unknown action). This is an internal invariant: the WPF code constructs the args itself, so this signals a corrupted or unforeseen change action, not a caller mistake.","triggerScenarios":"A change-notification pipeline (Clear, Insert, Remove, RemoveAt, AddHelper) delivering an unrecognized NotifyCollectionChangedAction to OnCollectionChanged — practically only via custom NotifyCollectionChangedEventArgs with default action or future/invalid enum values.","commonSituations":"Custom collection-change plumbing that builds NotifyCollectionChangedEventArgs without specifying an action, enum casting bugs, mixing WPF FreezableCollection with code assuming different enum semantics.","solutions":["Audit code that constructs NotifyCollectionChangedEventArgs and always pass an explicit valid NotifyCollectionChangedAction.","Do not route foreign INotifyCollectionChanged events through FreezableCollection.OnCollectionChanged.","If it appears without custom code, report it as a WPF bug and capture a stack trace of the raising operation."],"exampleFix":"// before\nvar args = new NotifyCollectionChangedEventArgs(default, item);\n// after\nvar args = new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Add, item);","handlingStrategy":"validation","validationCode":"if (!Enum.IsDefined(typeof(NotifyCollectionChangedAction), action) || action == default)\n    throw new ArgumentException(\"action must be an explicit NotifyCollectionChangedAction value\");","typeGuard":"static bool IsValidAction(NotifyCollectionChangedAction a) => a is NotifyCollectionChangedAction.Add or Remove or Replace or Move or Reset;","tryCatchPattern":"try { OnCollectionChanged(args); }\ncatch (InvalidOperationException ex) when (ex.Message.Contains(\"change\")) { log.Error(\"Unexpected change action\", ex); }","preventionTips":["Always construct NotifyCollectionChangedEventArgs with an explicit action","Never pass default(NotifyCollectionChangedAction)","Do not bridge foreign collection-change events into FreezableCollection internals"],"tags":["wpf","collection-changed","enum","invariant"],"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-21T21:30:21.729Z"}