tursodatabase/turso · error · ArgumentException

Parameter type {valueType} is not supported

Error message

Parameter type {valueType} is not supported

What it means

TursoParameter.ToValue() converts the parameter's CLR Value into a TursoValue using a fixed type map; this ArgumentException fires when the runtime type of Value is not in the map. Supported types are: bool, byte, byte[], char, DateTime, DateTimeOffset, DateOnly, TimeOnly, DBNull, decimal, double, float, Guid, int, long, sbyte, short, string, TimeSpan, uint, ulong, ushort. Null converts to Turso NULL; everything else (enums, BigInteger, JsonElement, custom types) is rejected.

Source

Thrown at bindings/dotnet/src/Turso.Data/TursoParameter.cs:103

    public override object? Value { get; set; }
    public override bool SourceColumnNullMapping { get; set; }

    public TursoValue ToValue()
    {
        if (Value is null)
            return new TursoValue { ValueType = TursoValueType.Null };

        var value = Value;
        var valueType = value.GetType();
        if (valueType.IsEnum)
        {
            valueType = Enum.GetUnderlyingType(valueType);
            value = Convert.ChangeType(value, valueType, CultureInfo.InvariantCulture);
        }

        if (!TursoTypeMapping.TryGetValue(valueType, out var tursoValueType))
        {
            throw new ArgumentException($"Parameter type {valueType} is not supported");
        }

        return GetTursoValue(value, tursoValueType);
    }

    public override int Size
    {
        get => _size;
        set
        {
            ArgumentOutOfRangeException.ThrowIfLessThan(value, -1);
            _size = value;
        }
    }

    private static TursoValue GetTursoValue(object value, TursoValueType tursoValueType)
    {
        return tursoValueType switch

View on GitHub (pinned to 6c72522679)

Solutions

  1. Convert before binding: enums via Convert.ToInt64/ToString, JsonElement via .ToString() or GetRawText(), custom objects via an explicit serialization you control.
  2. For blobs use byte[]; for decimal/dates the provider already stringifies supported types, so just use the base CLR types.
  3. Wrap third-party numeric types with a cast to long/double/string at the call site.

Example fix

// before
cmd.Parameters.AddWithValue("@status", OrderStatus.Shipped); // enum -> not in map

// after
cmd.Parameters.AddWithValue("@status", (long)OrderStatus.Shipped);
Defensive patterns

Strategy: type-guard

Type guard

static readonly HashSet<Type> Supported = new()
{ typeof(bool), typeof(byte), typeof(byte[]), typeof(char), typeof(DateTime), typeof(DateTimeOffset),
  typeof(DateOnly), typeof(TimeOnly), typeof(DBNull), typeof(decimal), typeof(double), typeof(float),
  typeof(Guid), typeof(int), typeof(long), typeof(sbyte), typeof(short), typeof(string),
  typeof(TimeSpan), typeof(uint), typeof(ulong), typeof(ushort) };
static bool IsSupportedParameterValue(object? v) => v is null || Supported.Contains(v.GetType());

Try / catch

try { cmd.ExecuteNonQuery(); } catch (ArgumentException ex) when (ex.Message.Contains("Parameter type")) { /* identify the parameter, convert its value to a base CLR type */ }

Prevention

When it happens

Trigger: Assigning a parameter value whose GetType() is outside the map — e.g. an enum value, System.Text.Json.JsonElement, BigInteger, Microsoft.Data.Sqlite.SqlString, an anonymous/custom POCO, or a dynamic/ulong overflow value — and then executing the command (ExecuteNonQuery/Reader/Scalar calls ToValue during binding).

Common situations: Passing enum properties directly from domain models; deserializing JSON config into JsonElement and binding it; porting code from providers with broader type support (SqlClient maps SqlTypes, Npgsql maps many primitive types); nullable wrapper types like 'int?' boxed with a value but typed helpers producing custom numeric types.

Related errors


AI-assisted analysis of tursodatabase/turso@6c72522679 (2026-09-06). Data as JSON: /api/errors/08c75084acd8a984. Report an issue: GitHub.