{"record":{"id":"a0aa70f0e389d58a","repo":"stride3d/stride","slug":"resizing-transaction-stack-to-a-smaller-size-is-not","errorCode":null,"errorMessage":"Resizing transaction stack to a smaller size is not supported yet.","messagePattern":"Resizing transaction stack to a smaller size is not supported yet\\.","errorType":"exception","errorClass":"NotSupportedException","httpStatus":null,"severity":"warning","filePath":"sources/core/Stride.Core.Design/Transactions/TransactionStack.cs","lineNumber":272,"sourceCode":"            RollInProgress = true;\n            try\n            {\n                lastTransaction.Interface.Rollforward();\n            }\n            finally\n            {\n                RollInProgress = false;\n            }\n            TransactionRollforwarded?.Invoke(this, new TransactionEventArgs(lastTransaction));\n        }\n    }\n\n    public void Resize(int newCapacity)\n    {\n        if (newCapacity < Capacity)\n        {\n            // TODO: this is minor but we should support that (potential discard, properly trigger events, etc.)\n            throw new NotSupportedException(\"Resizing transaction stack to a smaller size is not supported yet.\");\n        }\n        lock (lockObject)\n        {\n            Capacity = newCapacity;\n        }\n    }\n\n    /// <summary>\n    /// Purges the stack from the given index (included) to the top of the stack.\n    /// </summary>\n    /// <param name=\"index\">The index from which to purge the stack.</param>\n    private void PurgeFromIndex(int index)\n    {\n        if (index < 0 || index > transactions.Count) throw new ArgumentOutOfRangeException(nameof(index));\n\n        if (transactions.Count > index)\n        {\n            var discardedTransactions = new IReadOnlyTransaction[transactions.Count - index];","sourceCodeStart":254,"sourceCodeEnd":290,"githubUrl":"https://github.com/stride3d/stride/blob/96fad776d210c221682aac1ccdf4c79dc046fc38/sources/core/Stride.Core.Design/Transactions/TransactionStack.cs#L254-L290","documentation":"TransactionStack.Resize() refuses to shrink the stack because shrinking would require discarding active transactions and firing events, which is not implemented (explicit TODO in source). Only growing the stack is supported. This is an intentional NotSupportedException guarding an unimplemented code path.","triggerScenarios":"Calling TransactionStack.Resize(newCapacity) with newCapacity < Capacity. Any attempt to reduce the reserved capacity while the stack exists, regardless of how many transactions are active.","commonSituations":"Reusing a stack across app phases and trying to compact it; dynamic capacity tuning that grows then shrinks; copying sizing logic that recalculates capacity from a smaller estimate.","solutions":["Only call Resize with a value >= Capacity; check the current Capacity first","If a smaller stack is truly needed, create a new TransactionStack and migrate/discard transactions explicitly","Track capacity growth monotonically in your code so you never request a shrink","Contribute/implement shrink support (discard + events) upstream if needed"],"exampleFix":"// before\nstack.Resize(desiredCapacity); // desiredCapacity may be < Capacity\n// after\nif (desiredCapacity > stack.Capacity)\n    stack.Resize(desiredCapacity);","handlingStrategy":"validation","validationCode":"if (newCapacity < stack.Capacity)\n    throw new InvalidOperationException($\"Cannot shrink TransactionStack (current {stack.Capacity}).\");\nstack.Resize(newCapacity);","typeGuard":null,"tryCatchPattern":"try { stack.Resize(n); }\ncatch (NotSupportedException) { /* allocate a new stack instead */ }","preventionTips":["Treat capacity as grow-only","Check Capacity before Resize","Centralize resize logic in one helper"],"tags":["transactions","unsupported-operation","csharp"],"backgroundTag":"unsupported-operation","analyzedSha":"96fad776d210c221682aac1ccdf4c79dc046fc38","analyzedAt":"2026-09-14T02:59:31.279Z","contentChangedAt":"2026-09-14T02:59:31.279Z","schemaVersion":2},"datasetVersion":"2026-09-15T23:17:13.987Z"}