{"record":{"id":"b9776c48d5486eb8","repo":"stride3d/stride","slug":"reset-is-not-supported-by-the-undo-stack","errorCode":null,"errorMessage":"Reset is not supported by the undo stack.","messagePattern":"Reset is not supported by the undo stack\\.","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"sources/presentation/Stride.Core.Presentation/Dirtiables/CollectionChangeOperation.cs","lineNumber":19,"sourceCode":"// Copyright (c) .NET Foundation and Contributors (https://dotnetfoundation.org/ & https://stride3d.net) and Silicon Studio Corp. (https://www.siliconstudio.co.jp)\n// Distributed under the MIT license. See the LICENSE.md file in the project root for more information.\n\nusing System.Collections;\nusing System.Collections.Specialized;\n\nnamespace Stride.Core.Presentation.Dirtiables;\n\npublic class CollectionChangeOperation : DirtyingOperation\n{\n    private readonly int index;\n    private IList? list;\n    private IReadOnlyCollection<object>? items;\n\n    private CollectionChangeOperation(IList list, NotifyCollectionChangedAction actionToUndo, IEnumerable<IDirtiable> dirtiables)\n        : base(dirtiables)\n    {\n        ArgumentNullException.ThrowIfNull(list);\n        if (actionToUndo == NotifyCollectionChangedAction.Reset) throw new ArgumentException(\"Reset is not supported by the undo stack.\");\n\n        ActionToUndo = actionToUndo;\n        this.list = list;\n    }\n\n    public CollectionChangeOperation(IList list, NotifyCollectionChangedAction actionToUndo, IReadOnlyCollection<object> items, int index, IEnumerable<IDirtiable> dirtiables)\n        : this(list, actionToUndo, dirtiables)\n    {\n        ArgumentNullException.ThrowIfNull(items);\n\n        this.items = items;\n        this.index = index;\n    }\n\n    public CollectionChangeOperation(IList list, NotifyCollectionChangedEventArgs args, IEnumerable<IDirtiable> dirtiables)\n        : this(list, args.Action, dirtiables)\n    {\n        switch (args.Action)","sourceCodeStart":1,"sourceCodeEnd":37,"githubUrl":"https://github.com/stride3d/stride/blob/96fad776d210c221682aac1ccdf4c79dc046fc38/sources/presentation/Stride.Core.Presentation/Dirtiables/CollectionChangeOperation.cs#L1-L37","documentation":"CollectionChangeOperation records undoable list changes for the undo stack. The private constructor validates a NotifyCollectionChangedAction and explicitly rejects Reset, which carries no per-item information to invert.","triggerScenarios":"Constructing a CollectionChangeOperation (via internal factories handling collection changes) where actionToUndo equals NotifyCollectionChangedAction.Reset, e.g. a Clear() or a bulk reset on an observed list wrapped by the dirtiables/undo system.","commonSituations":"Clearing a bound collection that participates in undo/redo; replacing a collection's contents wholesale so the framework sees a Reset event.","solutions":["Avoid Clear()/Reset-style operations on collections tracked by the undo stack; remove items individually so Add/Remove operations are recorded","Handle Reset separately in code that translates collection-changed events into undo operations","Clear the undo stack intentionally before performing the reset"],"exampleFix":"// before\nlist.Clear(); // produces Reset, unsupported by undo\n// after\nwhile (list.Count > 0) list.RemoveAt(list.Count - 1); // per-item undoable removals","handlingStrategy":"validation","validationCode":"if (args.Action == NotifyCollectionChangedAction.Reset) { /* clear undo stack instead of recording */ return; }","typeGuard":"bool IsUndoableAction(NotifyCollectionChangedAction a) => a is NotifyCollectionChangedAction.Add or NotifyCollectionChangedAction.Remove or NotifyCollectionChangedAction.Replace;","tryCatchPattern":"try { op = CreateCollectionChangeOperation(list, action, dirtiables); } catch (ArgumentException) { undoStack.Clear(); }","preventionTips":["Avoid Clear()/Reset on undo-tracked lists","Remove items individually for undoable clears","Pre-filter Reset notifications before recording"],"tags":["csharp","undo","collections"],"backgroundTag":"unsupported-operation","analyzedSha":"96fad776d210c221682aac1ccdf4c79dc046fc38","analyzedAt":"2026-09-14T02:59:31.279Z","contentChangedAt":"2026-09-14T02:59:31.279Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}