{"record":{"id":"7337f1950d60bbd7","repo":"dotnet/machinelearning","slug":"unknown-schema-type-schema-type","errorCode":null,"errorMessage":"unknown schema type: {schema.Type}","messagePattern":"unknown schema type: (.+?)","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.ML.SearchSpace/Converter/NumericOptionConverter.cs","lineNumber":46,"sourceCode":"            public object Min { get; set; }\n\n            [JsonPropertyName(\"max\")]\n            public object Max { get; set; }\n\n            [JsonPropertyName(\"log_base\")]\n            public bool LogBase { get; set; }\n        }\n\n        public override UniformNumericOption Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)\n        {\n            var schema = JsonSerializer.Deserialize<Schema>(ref reader, options);\n\n            return schema.Type switch\n            {\n                \"int\" => new UniformIntOption(Convert.ToInt32(schema.Min), Convert.ToInt32(schema.Max), schema.LogBase, Convert.ToInt32(schema.Default)),\n                \"float\" => new UniformSingleOption(Convert.ToSingle(schema.Min), Convert.ToSingle(schema.Max), schema.LogBase, Convert.ToSingle(schema.Default)),\n                \"double\" => new UniformDoubleOption(Convert.ToDouble(schema.Min), Convert.ToDouble(schema.Max), schema.LogBase, Convert.ToDouble(schema.Default)),\n                _ => throw new ArgumentException($\"unknown schema type: {schema.Type}\"),\n            };\n        }\n\n        public override void Write(Utf8JsonWriter writer, UniformNumericOption value, JsonSerializerOptions options)\n        {\n            var schema = value switch\n            {\n                UniformIntOption intOption => new Schema\n                {\n                    Type = \"int\",\n                    Default = intOption.SampleFromFeatureSpace(intOption.Default).AsType<int>(),\n                    Min = Convert.ToInt32(intOption.Min),\n                    Max = Convert.ToInt32(intOption.Max),\n                    LogBase = intOption.LogBase,\n                },\n                UniformDoubleOption doubleOption => new Schema\n                {\n                    Type = \"double\",","sourceCodeStart":28,"sourceCodeEnd":64,"githubUrl":"https://github.com/dotnet/machinelearning/blob/7b76e69cf964daeca3f1377af6bc5543284d56c6/src/Microsoft.ML.SearchSpace/Converter/NumericOptionConverter.cs#L28-L64","documentation":"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}'.","triggerScenarios":"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').","commonSituations":"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.","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."],"exampleFix":"// before (json)\n{ \"type\": \"integer\", \"min\": 1, \"max\": 10 }\n// after (json)\n{ \"type\": \"int\", \"min\": 1, \"max\": 10 }","handlingStrategy":"validation","validationCode":"// C#: validate schema type before deserializing\nstatic readonly HashSet<string> Allowed = new() { \"int\", \"float\", \"double\" };\nusing var doc = JsonDocument.Parse(json);\nvar type = doc.RootElement.GetProperty(\"type\").GetString();\nif (!Allowed.Contains(type))\n    throw new ArgumentException($\"Bad schema type '{type}'; expected int|float|double\");","typeGuard":"static bool IsKnownNumericSchemaType(string t) => t is \"int\" or \"float\" or \"double\";","tryCatchPattern":"try { opt = JsonSerializer.Deserialize<OptionBase>(json, options); }\ncatch (ArgumentException ex) when (ex.Message.StartsWith(\"unknown schema type\"))\n{\n    // normalize type field (integer->int, number->double) and retry\n}","preventionTips":["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."],"tags":["json","deserialization","searchspace","invalid-enum"],"backgroundTag":"unsupported-enum-value","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"}