{"record":{"id":"692b2b1c7aa75488","repo":"AvaloniaUI/Avalonia","slug":"reset-called-on-collection-without-reset-handler-692b2b","errorCode":null,"errorMessage":"Reset called on collection without reset handler.","messagePattern":"Reset called on collection without reset handler\\.","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"src/Avalonia.Base/Collections/AvaloniaListExtensions.cs","lineNumber":134,"sourceCode":"                        break;\n                    case NotifyCollectionChangedAction.Replace:\n                        if (e.OldStartingIndex < 0)\n                        {\n                            goto case NotifyCollectionChangedAction.Reset;\n                        }\n\n                        Remove(e.OldStartingIndex, e.OldItems!);\n                        Add(e.NewStartingIndex, e.NewItems!);\n                        break;\n\n                    case NotifyCollectionChangedAction.Remove:\n                        Remove(e.OldStartingIndex, e.OldItems!);\n                        break;\n\n                    case NotifyCollectionChangedAction.Reset:\n                        if (reset == null)\n                        {\n                            throw new InvalidOperationException(\n                                \"Reset called on collection without reset handler.\");\n                        }\n\n                        reset();\n                        Add(0, (IList)collection);\n                        break;\n                }\n            };\n\n            Add(0, (IList)collection);\n\n            if (weakSubscription)\n            {\n                return collection.WeakSubscribe(handler);\n            }\n            else\n            {\n                collection.CollectionChanged += handler;","sourceCodeStart":116,"sourceCodeEnd":152,"githubUrl":"https://github.com/AvaloniaUI/Avalonia/blob/11c542726898ae954a1ef668c65ec79ec92ab17d/src/Avalonia.Base/Collections/AvaloniaListExtensions.cs#L116-L152","documentation":"InvalidOperationException thrown by AvaloniaListExtensions.ForEachItem when the observed list raises a Reset collection-changed event but the caller did not supply a reset callback. Without a reset handler the tracker cannot rebuild its index-aware state after a wholesale reset, so it throws.","triggerScenarios":"Calling collection.ForEachItem(added, removed, reset: null) (or the 2-action overload that forwards null) on a list that later raises Reset (e.g. AvaloniaList.Clear or a Reset notification from an ObservableCollection).","commonSituations":"Observing a collection that is cleared/reloaded (filter refresh, data reload, theme change); using the simplified ForEachItem overload that omits the reset handler.","solutions":["Pass a non-null reset Action that clears/reinitializes your tracked state (it is followed by Add callbacks for the remaining items).","Suppress Reset on the source (avoid Clear raising Reset) or unsubscribe before reloading.","Use the overload that accepts (added, removed, reset) explicitly rather than the 2-action variant."],"exampleFix":"// before\nlist.ForEachItem(OnAdd, OnRemove, reset: null);\n\n// after\nlist.ForEachItem(OnAdd, OnRemove, () => { tracked.Clear(); });","handlingStrategy":"validation","validationCode":"if (canReset) collection.ForEachItem(OnAdd, OnRemove, () => tracked.Clear());","typeGuard":null,"tryCatchPattern":"try { list.ForEachItem(OnAdd, OnRemove, ResetHandler); }\ncatch (InvalidOperationException ex) when (ex.Message.Contains(\"reset handler\")) { /* rebuild index-aware state */ }","preventionTips":["Always provide a reset Action when observing clearable lists.","Use the 3-action ForEachItem overload explicitly.","Dispose subscriptions before reloading the source list."],"tags":["avalonia","collections","list","reactive","collection-changed"],"backgroundTag":null,"analyzedSha":"11c542726898ae954a1ef668c65ec79ec92ab17d","analyzedAt":"2026-08-13T11:57:40.261Z","schemaVersion":2},"datasetVersion":"2026-08-13T14:17:21.547Z"}