litedb-org/LiteDB · error · InvalidOperationException
LiteException did not contain expected message. Actual: {obs
Error message
LiteException did not contain expected message. Actual: {observedException.Message} What it means
Thrown by the Issue 2561 repro harness when a LiteException was observed from ReleaseTransaction but its message did not contain 'current thread must contains transaction parameter'. The repro asserts not just that an exception fired, but that it carries the specific thread-affinity diagnostic. A different message means the failure mode shifted from the documented one.
Source
Thrown at LiteDB.ReproRunner/Repros/Issue_2561_TransactionMonitor/Program.cs:149
};
worker.Start();
if (!reproObserved.Wait(TimeSpan.FromSeconds(10)))
{
throw new TimeoutException("Timed out waiting for ReleaseTransaction to finish.");
}
rollback.Invoke(engine, Array.Empty<object>());
if (observedException is null)
{
throw new InvalidOperationException("Expected LiteException was not observed.");
}
if (!observedException.Message.Contains("current thread must contains transaction parameter", StringComparison.OrdinalIgnoreCase))
{
throw new InvalidOperationException($"LiteException did not contain expected message. Actual: {observedException.Message}");
}
Log(host, "Repro succeeded: ReleaseTransaction threw on the wrong thread.");
}
private static void Log(ReproHostClient host, string message, ReproHostLogLevel level = ReproHostLogLevel.Information)
{
host.SendLog(message, level);
if (level >= ReproHostLogLevel.Warning)
{
Console.Error.WriteLine(message);
}
else
{
Console.WriteLine(message);
}
}View on GitHub (pinned to f906a5f850)
Solutions
- Read observedException.Message from the log to see the actual failure, then reconcile it with the expected thread-affinity text.
- Update the expected substring to match the current LiteDB message if the wording was intentionally changed.
- Ensure the main thread holds the transaction open (no early Rollback/Commit) until after the worker invokes ReleaseTransaction.
- Confirm the repro uses the same LiteDB build whose message string it asserts against.
Example fix
// before
if (!observedException.Message.Contains("current thread must contains transaction parameter", StringComparison.OrdinalIgnoreCase))
{
throw new InvalidOperationException($"LiteException did not contain expected message. Actual: {observedException.Message}");
}
// after
var expectedFragments = new[] { "current thread must contains transaction parameter", "transaction parameter" };
if (!expectedFragments.Any(f => observedException.Message.Contains(f, StringComparison.OrdinalIgnoreCase)))
{
throw new InvalidOperationException($"LiteException did not contain expected message. Actual: {observedException.Message}");
} Defensive patterns
Strategy: validation
Validate before calling
// Relax the assertion to a set of known-good fragments
var acceptableFragments = new[] { "current thread must contains transaction parameter", "transaction parameter", "wrong thread" };
bool ok = observedException != null && acceptableFragments.Any(f => observedException.Message.Contains(f, StringComparison.OrdinalIgnoreCase)); Prevention
- Do not assert on exact exception wording; match against the semantic invariant.
- Log the full observedException.ToString() so the actual message is recoverable.
- Keep the expected-message list in sync with the LiteDB version under test.
When it happens
Trigger: ReleaseTransaction threw a LiteException on the wrong thread, but with a different message (e.g. a 'transaction not found', 'transaction already released', or a localized/altered string). Happens when the exception text was edited, or when the captured transaction was already released and the monitor throws a different error before reaching the thread-affinity check.
Common situations: LiteDB version change that reworded the thread-affinity exception message, or a repro ordering change where the main thread already rolled back before the worker invoked ReleaseTransaction, causing a stale-transaction error instead.
Related errors
- Expected LiteException was not observed.
- Timed out waiting for ReleaseTransaction to finish.
- Failed to begin primary transaction for reproduction.
- ENTITY_INITIALIZATION_FAILED
- 0
AI-assisted analysis of litedb-org/LiteDB@f906a5f850 (2026-08-13).
Data as JSON: /api/errors/6503ff154a5f4067.
Report an issue: GitHub.