dotnet/machinelearning · error · ArgumentException
unknown schema type: {schema.Type}
Error message
unknown schema type: {schema.Type} What it means
NumericOptionConverter.Read deserializes a JSON schema object into a concrete numeric option. The schema's 'type' string must be one of 'int', 'float', or 'double'; any other value throws ArgumentException 'unknown schema type: {schema.Type}'.
Source
Thrown at src/Microsoft.ML.SearchSpace/Converter/NumericOptionConverter.cs:46
public object Min { get; set; }
[JsonPropertyName("max")]
public object Max { get; set; }
[JsonPropertyName("log_base")]
public bool LogBase { get; set; }
}
public override UniformNumericOption Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
{
var schema = JsonSerializer.Deserialize<Schema>(ref reader, options);
return schema.Type switch
{
"int" => new UniformIntOption(Convert.ToInt32(schema.Min), Convert.ToInt32(schema.Max), schema.LogBase, Convert.ToInt32(schema.Default)),
"float" => new UniformSingleOption(Convert.ToSingle(schema.Min), Convert.ToSingle(schema.Max), schema.LogBase, Convert.ToSingle(schema.Default)),
"double" => new UniformDoubleOption(Convert.ToDouble(schema.Min), Convert.ToDouble(schema.Max), schema.LogBase, Convert.ToDouble(schema.Default)),
_ => throw new ArgumentException($"unknown schema type: {schema.Type}"),
};
}
public override void Write(Utf8JsonWriter writer, UniformNumericOption value, JsonSerializerOptions options)
{
var schema = value switch
{
UniformIntOption intOption => new Schema
{
Type = "int",
Default = intOption.SampleFromFeatureSpace(intOption.Default).AsType<int>(),
Min = Convert.ToInt32(intOption.Min),
Max = Convert.ToInt32(intOption.Max),
LogBase = intOption.LogBase,
},
UniformDoubleOption doubleOption => new Schema
{
Type = "double",View on GitHub (pinned to 7b76e69cf9)
Solutions
- Fix the JSON so type is exactly "int", "float", or "double" (lowercase).
- Validate the schema file against the expected shape before deserializing.
- If the source schema uses other names, map them (integer→int, number→double) before conversion.
- Ensure you're deserializing with the correct target type; a numeric option JSON should not carry other type tags.
Example fix
// before (json)
{ "type": "integer", "min": 1, "max": 10 }
// after (json)
{ "type": "int", "min": 1, "max": 10 } Defensive patterns
Strategy: validation
Validate before calling
// C#: validate schema type before deserializing
static readonly HashSet<string> Allowed = new() { "int", "float", "double" };
using var doc = JsonDocument.Parse(json);
var type = doc.RootElement.GetProperty("type").GetString();
if (!Allowed.Contains(type))
throw new ArgumentException($"Bad schema type '{type}'; expected int|float|double"); Type guard
static bool IsKnownNumericSchemaType(string t) => t is "int" or "float" or "double";
Try / catch
try { opt = JsonSerializer.Deserialize<OptionBase>(json, options); }
catch (ArgumentException ex) when (ex.Message.StartsWith("unknown schema type"))
{
// normalize type field (integer->int, number->double) and retry
} Prevention
- Generate search-space JSON only through the library's serializer, not by hand.
- Normalize foreign schema type names before deserialization.
- Add a JSON schema validation step in configs pipeline.
When it happens
Trigger: Deserializing JSON into OptionBase/UniformNumericOption via OptionConverter/NumericOptionConverter when the JSON contains type values other than int/float/double (e.g. 'integer', 'long', 'number', or a hand-written/foreign schema with type 'string').
Common situations: Hand-authoring or generating search-space JSON with non-ML.NET type names; schema files produced by a different tool/version; typos in the type field; JSON edited manually and type field corrupted.
Related errors
- unknown type
- unknown option type
- Unsupported reader type {reader.TokenType}
- Problems met when parsing JSON vocabulary object.{Environmen
- Problems met when parsing JSON vocabulary object.{Environmen
AI-assisted analysis of dotnet/machinelearning@7b76e69cf9 (2026-09-11).
Data as JSON: /api/errors/7337f1950d60bbd7.
Report an issue: GitHub.