stride3d/stride · error · TransactionException
Unable to rollback. This method cannot be invoked when…
Error message
Unable to rollback. This method cannot be invoked when CanRollback is false.
What it means
TransactionStack.Rollback() can only undo a transaction when CanRollback is true, which requires the undo position (currentPosition) to be greater than 0. This error is thrown when Rollback is called with nothing left to undo.
Solutions
- Check transactionStack.CanRollback before calling Rollback.
- Disable/gray out the Undo action when CanRollback is false (subscribe to property-change updates).
- Update UI state after each Rollback so the guard reflects the new position.
- Catch TransactionException around Rollback as a defensive fallback for concurrent undo triggers.
Example fix
// before
stack.Rollback();
// after
if (stack.CanRollback)
stack.Rollback(); Defensive patterns
Strategy: validation
Validate before calling
if (transactionStack.CanRollback)
transactionStack.Rollback(); Type guard
bool CanUndo(TransactionStack stack) => stack.CanRollback;
Try / catch
try
{
transactionStack.Rollback();
}
catch (TransactionException ex) when (ex.Message.Contains("CanRollback is false"))
{
// nothing to undo; update UI state
} Prevention
- Gate undo commands on CanRollback.
- Subscribe to CanRollback change notifications to enable/disable UI.
- Refresh guards after every rollback/clear.
When it happens
Trigger: Calling transactionStack.Rollback() when currentPosition == 0 (no transactions have been executed, or all were already undone).
Common situations: Undo button/action invoked repeatedly until history is exhausted; calling Rollback on a freshly created or just-Clear()ed stack; multiple Rollback calls racing so the last one finds an empty undo range.
Understand the failure class
Background: "Invalid state transition" errors: "status must be X, actually Y", "already rejected/charging/uninstalled", "cannot ... while running" — what they mean when a library rejects your call — this error's family across 31 libraries.
Related errors
- There is no transaction in progress in the transaction…
- There is not transaction in progress in the transaction…
- Unable to rollback. A transaction is in progress.
- Unable to rollforward. This method cannot be invoked when…
- The transaction being completed is not that last created…
AI-assisted analysis of stride3d/stride@96fad776d2 (2026-09-14).
Data as JSON: /api/errors/4601eb1175c5638e.
Report an issue: GitHub.
Appendix: source
Thrown at sources/core/Stride.Core.Design/Transactions/TransactionStack.cs:221
}
// Complete parent transactions
if ((transaction.Flags & TransactionFlags.KeepParentsAlive) != 0)
{
foreach (var parentTransaction in transactionsInProgress.Reverse())
parentTransaction.Complete();
}
}
}
}
/// <inheritdoc/>
public void Rollback()
{
lock (lockObject)
{
if (!CanRollback)
throw new TransactionException("Unable to rollback. This method cannot be invoked when CanRollback is false.");
if (RollInProgress)
throw new TransactionException("Unable to rollback. A rollback or rollforward operation is already in progress.");
if (transactionsInProgress.Count > 0)
throw new TransactionException("Unable to rollback. A transaction is in progress.");
var lastTransaction = transactions[--currentPosition];
RollInProgress = true;
try
{
lastTransaction.Interface.Rollback();
}
finally
{
RollInProgress = false;
}
TransactionRollbacked?.Invoke(this, new TransactionEventArgs(lastTransaction));
}
}View on GitHub (pinned to 96fad776d2)