dotnet/machinelearning · error · ArgumentException
Unsupported reader type {reader.TokenType}
Error message
Unsupported reader type {reader.TokenType} What it means
ParameterConverter.Read deserializes a Parameter from JSON by inspecting the Utf8JsonReader's TokenType. When it encounters a JSON token type it does not know how to convert (e.g. null, StartObject, or other unhandled tokens), it falls through to the default case and throws ArgumentException listing the unsupported token type.
Source
Thrown at src/Microsoft.ML.SearchSpace/Converter/ParameterConverter.cs:50
}
return Parameter.FromDouble(JsonSerializer.Deserialize<double>(ref reader, options));
case JsonTokenType.True:
return Parameter.FromBool(true);
case JsonTokenType.False:
return Parameter.FromBool(false);
case JsonTokenType.Null:
return default(Parameter);
case JsonTokenType.StartArray:
var list = new List<object>();
while (reader.Read() && reader.TokenType != JsonTokenType.EndArray)
{
list.Add(Read(ref reader, null, options));
}
return Parameter.FromIEnumerable(list);
default:
throw new ArgumentException($"Unsupported reader type {reader.TokenType}");
}
}
public override void Write(Utf8JsonWriter writer, Parameter value, JsonSerializerOptions options)
{
JsonSerializer.Serialize(writer, value.Value, options);
}
}
}
View on GitHub (pinned to 7b76e69cf9)
Solutions
- Inspect the JSON being deserialized and remove or correct the unsupported token (e.g. replace null with a concrete value or use the parameter's default).
- Ensure the JSON shape matches what the converter supports: scalars, arrays of scalars, or strings — not arbitrary nested objects.
- Wrap deserialization in try-catch and fall back to a default Parameter/Option instance when the payload is malformed.
- If a legitimately needed token type is unsupported, extend the converter's Read switch to handle it and return the appropriate Parameter.From* value.
Example fix
// before
var p = JsonSerializer.Deserialize<Parameter>(json);
// after
Parameter p;
try { p = JsonSerializer.Deserialize<Parameter>(json); }
catch (ArgumentException) { p = new SearchSpace<MyOptions>().ToList()[0]; // or build a default
} Defensive patterns
Strategy: try-catch
Validate before calling
using var doc = JsonDocument.Parse(json);
if (doc.RootElement.ValueKind == JsonValueKind.Null)
throw new FormatException("Parameter JSON must not be null"); Try / catch
try { p = JsonSerializer.Deserialize<Parameter>(json); }
catch (ArgumentException ex) { log.Warn(ex.Message); p = defaultParameter; } Prevention
- Never write null literals into tuning-space JSON payloads
- Validate JSON structure against the converter's supported token types before deserializing
- Keep serialization and deserialization on the same Parameter schema version
When it happens
Trigger: Deserializing a JSON payload into Microsoft.ML.SearchSpace.Parameter (via JsonSerializer.Deserialize<Parameter> or SearchSpace conversion) whose JSON contains a token type the converter doesn't handle — typically a null literal, an unexpected object/array shape, or corrupted JSON.
Common situations: Hand-edited or generated tuning-space JSON/config files containing null values; passing a JSON string with an unexpected structure (e.g. an object where a scalar, array, or string was expected); deserializing a serialized Parameter that was produced by a different schema version.
Understand the failure class
Background: "Invalid ... format", "must be in format X", "does not look like a ..." — invalid argument format errors across CLI tools and libraries — this error's family across 17 libraries.
Related errors
- unknown schema type: {schema.Type}
- unknown option type
- Problems met when parsing JSON vocabulary object.{Environmen
- Problems met when parsing JSON vocabulary object.{Environmen
- Invalid JSON.
AI-assisted analysis of dotnet/machinelearning@7b76e69cf9 (2026-09-11).
Data as JSON: /api/errors/0ee6c8082fc671c2.
Report an issue: GitHub.