tursodatabase/turso · error · InvalidOperationException
Unknown Turso sync operation state.
Error message
Unknown Turso sync operation state.
What it means
DriveOperationAsync loops over states returned by a sync operation handle (Ok/Continue/Io handled above). If the underlying runtime ever returns a TursoSyncOperationState the .NET driver does not recognize, it throws InvalidOperationException as a defensive default — meaning the native/Rust core and the .NET enum are out of sync.
Source
Thrown at bindings/dotnet/src/Turso.Data/TursoSyncDatabase.cs:360
TursoSyncOperationKind operationKind,
CancellationToken cancellationToken)
{
try
{
while (true)
{
cancellationToken.ThrowIfCancellationRequested();
switch (TursoSyncBindings.Resume(operation))
{
case TursoSyncOperationState.Done:
return;
case TursoSyncOperationState.Continue:
continue;
case TursoSyncOperationState.Io:
await ProcessIoQueueAsync(cancellationToken).ConfigureAwait(false);
break;
default:
throw new InvalidOperationException("Unknown Turso sync operation state.");
}
}
}
catch (OperationCanceledException) when (cancellationToken.IsCancellationRequested)
{
try
{
CancelQueuedIo();
}
catch
{
// Preserve cancellation after making the best effort to release native callbacks.
}
throw;
}
catch (TursoSyncException)
{
throw;View on GitHub (pinned to 6c72522679)
Solutions
- Align versions: update the Turso.Data NuGet package and the native turso library to matching releases.
- If pinning native libraries (e.g. via custom build), rebuild both from the same source revision.
- Reproduce with a minimal sync workload and report upstream if versions already match.
Example fix
// before <PackageReference Include="Turso.Data" Version="0.1.0" /> + mismatched native lib // after <PackageReference Include="Turso.Data" Version="0.2.0" /> // matching native library
Defensive patterns
Strategy: try-catch
Validate before calling
// check versions before opening var managed = typeof(TursoConnection).Assembly.GetName().Version; // ensure the pinned native turso library matches the managed package version
Try / catch
try
{
await connection.SyncAsync(ct);
}
catch (InvalidOperationException ex) when (ex.Message.Contains("Unknown Turso sync operation state"))
{
throw new InvalidOperationException("Native library and Turso.Data versions are out of sync. Align both.", ex);
} Prevention
- Ship the native library bundled with the NuGet package; never mix versions.
- Pin both managed and native artifacts to the same release in CI.
When it happens
Trigger: A sync operation (PullAsync, GetStatsAsync, ConnectHandleAsync, RunVoidOperationAsync) yields an operation state value not covered by the switch (only Continue and Io are matched in the shown default path), typically from a newer native library with new states used against an older managed binding.
Common situations: Version mismatch between the native turso library and the Turso.Data package; corrupted or unexpectedly completed sync operation handles.
Related errors
- Unknown Turso sync I/O request.
- Expected Turso sync result {expected}, got {actual}.
- Automatic sync is not supported for embedded replica connect
- Turso sync operations cannot be reentered from the sync HTTP
- Unknown result type: ${resultKind}
AI-assisted analysis of tursodatabase/turso@6c72522679 (2026-08-31).
Data as JSON: /api/errors/7bdee18cc9f9e0a4.
Report an issue: GitHub.