stride3d/stride · warning · NotSupportedException

Resizing transaction stack to a smaller size is not…

Error message

Resizing transaction stack to a smaller size is not supported yet.

What it means

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.

Solutions

  1. Only call Resize with a value >= Capacity; check the current Capacity first
  2. If a smaller stack is truly needed, create a new TransactionStack and migrate/discard transactions explicitly
  3. Track capacity growth monotonically in your code so you never request a shrink
  4. Contribute/implement shrink support (discard + events) upstream if needed

Example fix

// before
stack.Resize(desiredCapacity); // desiredCapacity may be < Capacity
// after
if (desiredCapacity > stack.Capacity)
    stack.Resize(desiredCapacity);
Defensive patterns

Strategy: validation

Validate before calling

if (newCapacity < stack.Capacity)
    throw new InvalidOperationException($"Cannot shrink TransactionStack (current {stack.Capacity}).");
stack.Resize(newCapacity);

Try / catch

try { stack.Resize(n); }
catch (NotSupportedException) { /* allocate a new stack instead */ }

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Understand the failure class

Background: UnsupportedOperationException and "is not supported" errors: when a library deliberately refuses a call — this error's family across 30 libraries.

Related errors


AI-assisted analysis of stride3d/stride@96fad776d2 (2026-09-14). Data as JSON: /api/errors/a0aa70f0e389d58a. Report an issue: GitHub.

Appendix: source

Thrown at sources/core/Stride.Core.Design/Transactions/TransactionStack.cs:272

            RollInProgress = true;
            try
            {
                lastTransaction.Interface.Rollforward();
            }
            finally
            {
                RollInProgress = false;
            }
            TransactionRollforwarded?.Invoke(this, new TransactionEventArgs(lastTransaction));
        }
    }

    public void Resize(int newCapacity)
    {
        if (newCapacity < Capacity)
        {
            // TODO: this is minor but we should support that (potential discard, properly trigger events, etc.)
            throw new NotSupportedException("Resizing transaction stack to a smaller size is not supported yet.");
        }
        lock (lockObject)
        {
            Capacity = newCapacity;
        }
    }

    /// <summary>
    /// Purges the stack from the given index (included) to the top of the stack.
    /// </summary>
    /// <param name="index">The index from which to purge the stack.</param>
    private void PurgeFromIndex(int index)
    {
        if (index < 0 || index > transactions.Count) throw new ArgumentOutOfRangeException(nameof(index));

        if (transactions.Count > index)
        {
            var discardedTransactions = new IReadOnlyTransaction[transactions.Count - index];

View on GitHub (pinned to 96fad776d2)