{"record":{"id":"e21bc0bfbb84cee7","repo":"tursodatabase/turso","slug":"cannot-convert-remote-type-value-to-int64","errorCode":null,"errorMessage":"Cannot convert remote {Type} value to Int64.","messagePattern":"Cannot convert remote (.+?) value to Int64\\.","errorType":"exception","errorClass":"InvalidCastException","httpStatus":null,"severity":"error","filePath":"bindings/dotnet/src/Turso.Data/TursoRemoteClient.cs","lineNumber":676,"sourceCode":"        return Type switch\n        {\n            \"null\" => DBNull.Value,\n            \"integer\" => ParseInteger(),\n            \"float\" => ParseFloat(),\n            \"text\" => Value.GetString() ?? string.Empty,\n            \"blob\" => DecodeBase64(Base64 ?? string.Empty),\n            _ => throw new TursoException($\"Remote response returned unsupported value type: {Type}\"),\n        };\n    }\n\n    public long GetInt64()\n    {\n        return Type switch\n        {\n            \"integer\" => ParseInteger(),\n            \"float\" => checked((long)ParseFloat()),\n            \"text\" => long.Parse(Value.GetString() ?? \"\", CultureInfo.InvariantCulture),\n            _ => throw new InvalidCastException($\"Cannot convert remote {Type} value to Int64.\"),\n        };\n    }\n\n    public double GetDouble()\n    {\n        return Type switch\n        {\n            \"float\" => ParseFloat(),\n            \"integer\" => ParseInteger(),\n            \"text\" => double.Parse(Value.GetString() ?? \"\", CultureInfo.InvariantCulture),\n            _ => throw new InvalidCastException($\"Cannot convert remote {Type} value to Double.\"),\n        };\n    }\n\n    public decimal GetDecimal()\n    {\n        return Type switch\n        {","sourceCodeStart":658,"sourceCodeEnd":694,"githubUrl":"https://github.com/tursodatabase/turso/blob/6c7252267988c76e632af00a671e4b9788dfae13/bindings/dotnet/src/Turso.Data/TursoRemoteClient.cs#L658-L694","documentation":"GetInt64 on a reader column whose remote value type is not integer, float, or text. The switch has no arms for null or blob, so calling GetInt64 on a NULL column or a BLOB column throws InvalidCastException -- the remote protocol distinguishes NULL as its own type, and the typed getter refuses to invent a value for it.","triggerScenarios":"reader.GetInt64(i) on a remote connection where column i is NULL (most common), a BLOB, or an unsupported type. Text values take a long.Parse path, so non-numeric text instead throws FormatException.","commonSituations":"Nullable columns (COUNT(*)-style absent rows, LEFT JOIN misses, optional fields) read without an IsDBNull check; schema changes making a column nullable after code shipped; BLOB columns read with numeric getters.","solutions":["Check reader.IsDBNull(i) before GetInt64 and decide on a default (0, or skip the row).","Verify the column ordinal maps to the column you expect -- misaligned ordinals are a classic cause.","If the column can legitimately hold non-numeric text or blobs, read it as GetValue and convert explicitly.","Confirm the schema with a raw SELECT and adjust the query to COALESCE the column when a default is acceptable."],"exampleFix":"// before\nlong id = reader.GetInt64(0);\n\n// after\nlong id = reader.IsDBNull(0) ? 0L : reader.GetInt64(0);","handlingStrategy":"validation","validationCode":"if (reader.IsDBNull(ordinal))\n    return 0L; // or your domain default for NULL\nreturn reader.GetInt64(ordinal);","typeGuard":"static bool CanReadInt64(System.Data.Common.DbDataReader reader, int i) =>\n    !reader.IsDBNull(i)\n    && reader.GetFieldType(i) is Type t\n    && (t == typeof(long) || t == typeof(double) || t == typeof(string));","tryCatchPattern":"try { value = reader.GetInt64(i); }\ncatch (InvalidCastException) when (reader.IsDBNull(i))\n{\n    value = 0L; // NULL column: choose an explicit domain default\n}","preventionTips":["Always pair IsDBNull with typed getters for nullable columns.","Use COALESCE in SQL when a default is acceptable at the query level.","Name your columns in SELECT and read by name to avoid ordinal drift after schema changes.","Write a nullability integration test for every entity you map by hand."],"tags":["turso","dotnet","reader","invalid-cast","null-handling"],"backgroundTag":"invalid-cast-exception","analyzedSha":"6c7252267988c76e632af00a671e4b9788dfae13","analyzedAt":"2026-08-20T07:02:18.389Z","contentChangedAt":"2026-08-20T07:02:18.389Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}