{"record":{"id":"a4c2c0115b02fd73","repo":"tursodatabase/turso","slug":"cannot-buffer-a-batch-value-of-type-value-gettype","errorCode":null,"errorMessage":"Cannot buffer a batch value of type {value.GetType().FullName}.","messagePattern":"Cannot buffer a batch value of type (.+?)\\.","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"bindings/dotnet/src/Turso.Data/TursoBatch.cs","lineNumber":292,"sourceCode":"                Type = \"blob\",\n                Base64 = Convert.ToBase64String(bytes),\n            },\n            double number => new RemoteResponseValue\n            {\n                Type = \"float\",\n                Value = JsonSerializer.SerializeToElement(number),\n            },\n            long number => new RemoteResponseValue\n            {\n                Type = \"integer\",\n                Value = JsonSerializer.SerializeToElement(number),\n            },\n            string text => new RemoteResponseValue\n            {\n                Type = \"text\",\n                Value = JsonSerializer.SerializeToElement(text),\n            },\n            _ => throw new InvalidOperationException(\n                $\"Cannot buffer a batch value of type {value.GetType().FullName}.\"),\n        };\n    }\n\n    private TursoConnection ValidateBatch()\n    {\n        var connection = _connection ?? throw new InvalidOperationException(\"Connection must be set before executing a batch.\");\n        if (connection.State != ConnectionState.Open)\n            throw new InvalidOperationException(\"Turso database is closed.\");\n        if (_transaction is { IsCompleted: true })\n            throw new InvalidOperationException(\"The transaction associated with this batch has completed.\");\n        if (_transaction is not null && !ReferenceEquals(_transaction.Connection, connection))\n            throw new InvalidOperationException(\"The transaction is not associated with the batch's connection.\");\n        if (_batchCommands.Count == 0)\n            throw new InvalidOperationException(\"Batch must contain at least one command.\");\n\n        foreach (var command in _batchCommands.AsReadOnly())\n        {","sourceCodeStart":274,"sourceCodeEnd":310,"githubUrl":"https://github.com/tursodatabase/turso/blob/6c7252267988c76e632af00a671e4b9788dfae13/bindings/dotnet/src/Turso.Data/TursoBatch.cs#L274-L310","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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."],"exampleFix":"// before\nSELECT myCustomValue() FROM t; // returns unsupported type\n// after\nSELECT CAST(myCustomValue() AS TEXT) FROM t;","handlingStrategy":"try-catch","validationCode":"foreach (DataColumn c in schemaTable.Columns)\n    if (!new[] { typeof(long), typeof(double), typeof(string), typeof(byte[]) }.Contains(c.DataType))\n        throw new InvalidOperationException($\"Column {c.ColumnName} type {c.DataType} not batch-bufferable.\");","typeGuard":null,"tryCatchPattern":"try { results.AddRange(await batch.ExecuteBatchAsync(ct)); }\ncatch (InvalidOperationException ex) when (ex.Message.StartsWith(\"Cannot buffer a batch value\"))\n{ /* execute that command individually or CAST the column */ }","preventionTips":["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."],"tags":["csharp","dotnet","batch","type-mismatch"],"backgroundTag":"type-mismatch","analyzedSha":"6c7252267988c76e632af00a671e4b9788dfae13","analyzedAt":"2026-09-06T07:15:26.990Z","contentChangedAt":"2026-09-06T07:15:26.990Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}