{"record":{"id":"0ee6c8082fc671c2","repo":"dotnet/machinelearning","slug":"unsupported-reader-type-reader-tokentype","errorCode":null,"errorMessage":"Unsupported reader type {reader.TokenType}","messagePattern":"Unsupported reader type (.+?)","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.ML.SearchSpace/Converter/ParameterConverter.cs","lineNumber":50,"sourceCode":"                    }\n\n                    return Parameter.FromDouble(JsonSerializer.Deserialize<double>(ref reader, options));\n                case JsonTokenType.True:\n                    return Parameter.FromBool(true);\n                case JsonTokenType.False:\n                    return Parameter.FromBool(false);\n                case JsonTokenType.Null:\n                    return default(Parameter);\n                case JsonTokenType.StartArray:\n                    var list = new List<object>();\n                    while (reader.Read() && reader.TokenType != JsonTokenType.EndArray)\n                    {\n                        list.Add(Read(ref reader, null, options));\n                    }\n\n                    return Parameter.FromIEnumerable(list);\n                default:\n                    throw new ArgumentException($\"Unsupported reader type {reader.TokenType}\");\n            }\n        }\n\n        public override void Write(Utf8JsonWriter writer, Parameter value, JsonSerializerOptions options)\n        {\n            JsonSerializer.Serialize(writer, value.Value, options);\n        }\n    }\n}\n","sourceCodeStart":32,"sourceCodeEnd":60,"githubUrl":"https://github.com/dotnet/machinelearning/blob/7b76e69cf964daeca3f1377af6bc5543284d56c6/src/Microsoft.ML.SearchSpace/Converter/ParameterConverter.cs#L32-L60","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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."],"exampleFix":"// before\nvar p = JsonSerializer.Deserialize<Parameter>(json);\n// after\nParameter p;\ntry { p = JsonSerializer.Deserialize<Parameter>(json); }\ncatch (ArgumentException) { p = new SearchSpace<MyOptions>().ToList()[0]; // or build a default\n}","handlingStrategy":"try-catch","validationCode":"using var doc = JsonDocument.Parse(json);\nif (doc.RootElement.ValueKind == JsonValueKind.Null)\n    throw new FormatException(\"Parameter JSON must not be null\");","typeGuard":null,"tryCatchPattern":"try { p = JsonSerializer.Deserialize<Parameter>(json); }\ncatch (ArgumentException ex) { log.Warn(ex.Message); p = defaultParameter; }","preventionTips":["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"],"tags":["json","deserialization","argument-exception","unsupported-token"],"backgroundTag":"invalid-argument-format","analyzedSha":"7b76e69cf964daeca3f1377af6bc5543284d56c6","analyzedAt":"2026-09-11T12:35:38.930Z","contentChangedAt":"2026-09-11T12:35:38.930Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}