tursodatabase/turso · error · InvalidOperationException
Cannot buffer a batch value of type {value.GetType().FullNam
Error message
Cannot buffer a batch value of type {value.GetType().FullName}. What it means
ToBufferedValue converts an executed batch command's result value into a buffered RemoteResponseValue. Only a fixed set of types (e.g. integer, real, text, blob) is supported; any other runtime type reaches the default branch and throws InvalidOperationException naming the actual type.
Source
Thrown at bindings/dotnet/src/Turso.Data/TursoBatch.cs:292
Type = "blob",
Base64 = Convert.ToBase64String(bytes),
},
double number => new RemoteResponseValue
{
Type = "float",
Value = JsonSerializer.SerializeToElement(number),
},
long number => new RemoteResponseValue
{
Type = "integer",
Value = JsonSerializer.SerializeToElement(number),
},
string text => new RemoteResponseValue
{
Type = "text",
Value = JsonSerializer.SerializeToElement(text),
},
_ => throw new InvalidOperationException(
$"Cannot buffer a batch value of type {value.GetType().FullName}."),
};
}
private TursoConnection ValidateBatch()
{
var connection = _connection ?? throw new InvalidOperationException("Connection must be set before executing a batch.");
if (connection.State != ConnectionState.Open)
throw new InvalidOperationException("Turso database is closed.");
if (_transaction is { IsCompleted: true })
throw new InvalidOperationException("The transaction associated with this batch has completed.");
if (_transaction is not null && !ReferenceEquals(_transaction.Connection, connection))
throw new InvalidOperationException("The transaction is not associated with the batch's connection.");
if (_batchCommands.Count == 0)
throw new InvalidOperationException("Batch must contain at least one command.");
foreach (var command in _batchCommands.AsReadOnly())
{View on GitHub (pinned to 6c72522679)
Solutions
- Cast or convert the offending column to a supported type (long, double, string, byte[]) in the SQL (e.g. CAST(col AS TEXT)).
- Catch InvalidOperationException and fall back to executing that command outside the batch.
- Report/upgrade the SDK if a standard SQLite type is being materialized as an unsupported CLR type.
Example fix
// before SELECT myCustomValue() FROM t; // returns unsupported type // after SELECT CAST(myCustomValue() AS TEXT) FROM t;
Defensive patterns
Strategy: try-catch
Validate before calling
foreach (DataColumn c in schemaTable.Columns)
if (!new[] { typeof(long), typeof(double), typeof(string), typeof(byte[]) }.Contains(c.DataType))
throw new InvalidOperationException($"Column {c.ColumnName} type {c.DataType} not batch-bufferable."); Try / catch
try { results.AddRange(await batch.ExecuteBatchAsync(ct)); }
catch (InvalidOperationException ex) when (ex.Message.StartsWith("Cannot buffer a batch value"))
{ /* execute that command individually or CAST the column */ } Prevention
- CAST exotic extension results to TEXT/INTEGER in batched SQL.
- Keep batched queries to standard SQLite types.
- Test batch execution against all extensions you use.
When it happens
Trigger: A batch command returns a column value whose CLR materialized type is outside the supported set — a custom scalar/aggregate extension return, an unexpected value type from the remote result, or a null-handling mismatch producing an unhandled type.
Common situations: Using extensions (e.g. vector, JSON) whose result values materialize as unsupported CLR types inside a batch on a sync database; upgrading Turso server so results return a new type the buffering code doesn't know.
Understand the failure class
Background: Type mismatch errors: IllegalArgumentException, TypeError and type guards across 150 open-source libraries — this error's family across 150 libraries.
Related errors
- Batch command must be a TursoBatchCommand.
- Parameter {value} is not a TursoParameter
- Connection must be a SqliteConnection.
- Transaction must be a SqliteTransaction.
- Turso batch execution requires a direct remote or embedded r
AI-assisted analysis of tursodatabase/turso@6c72522679 (2026-09-06).
Data as JSON: /api/errors/a4c2c0115b02fd73.
Report an issue: GitHub.