{"record":{"id":"f7179ed367b16333","repo":"dotnet/machinelearning","slug":"unknown-type","errorCode":null,"errorMessage":"unknown type","messagePattern":"unknown type","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.ML.SearchSpace/Converter/NumericOptionConverter.cs","lineNumber":78,"sourceCode":"                    LogBase = intOption.LogBase,\n                },\n                UniformDoubleOption doubleOption => new Schema\n                {\n                    Type = \"double\",\n                    Default = doubleOption.SampleFromFeatureSpace(doubleOption.Default).AsType<double>(),\n                    Min = doubleOption.Min,\n                    Max = doubleOption.Max,\n                    LogBase = doubleOption.LogBase,\n                },\n                UniformSingleOption singleOption => new Schema\n                {\n                    Type = \"float\",\n                    Default = singleOption.SampleFromFeatureSpace(singleOption.Default).AsType<Single>(),\n                    Min = Convert.ToSingle(singleOption.Min),\n                    Max = Convert.ToSingle(singleOption.Max),\n                    LogBase = singleOption.LogBase,\n                },\n                _ => throw new ArgumentException(\"unknown type\"),\n            };\n\n            JsonSerializer.Serialize(writer, schema, options);\n        }\n    }\n}\n","sourceCodeStart":60,"sourceCodeEnd":85,"githubUrl":"https://github.com/dotnet/machinelearning/blob/7b76e69cf964daeca3f1377af6bc5543284d56c6/src/Microsoft.ML.SearchSpace/Converter/NumericOptionConverter.cs#L60-L85","documentation":"NumericOptionConverter.Write serializes a UniformNumericOption to its schema JSON by switching on the runtime type (UniformIntOption/UniformSingleOption/UniformDoubleOption). If the value is a numeric option of another derived type, the default arm throws ArgumentException 'unknown type'.","triggerScenarios":"Serializing an OptionBase value that is a UniformNumericOption subclass not handled by the switch (e.g. a custom derived option type), via JsonSerializer with OptionConverter registered.","commonSituations":"Defining a custom numeric option subclass and putting it in a SearchSpace that gets serialized; library version mismatch where a new option type exists but the converter wasn't updated; putting the wrong object in a field typed as numeric option.","solutions":["Serialize only built-in UniformIntOption/UniformSingleOption/UniformDoubleOption instances.","If you have a custom subclass, convert it to a base type (e.g. copy Min/Max/Default into a UniformDoubleOption) before serialization.","Extend/patch the converter's switch to handle your derived type.","Check that the object placed in the search space is actually the intended numeric option type."],"exampleFix":"// before\nOptionBase opt = new MyCustomNumericOption(...);\nJsonSerializer.Serialize(writer, opt, options); // throws\n// after\nvar asDouble = new UniformDoubleOption(opt.Min, opt.Max, false, opt.Default);\nJsonSerializer.Serialize(writer, asDouble, options);","handlingStrategy":"type-guard","validationCode":"// C#: only serialize known numeric option types\nstatic bool IsSerializableNumericOption(OptionBase o) =>\n    o is UniformIntOption or UniformSingleOption or UniformDoubleOption;","typeGuard":"static bool IsBuiltInNumericOption(OptionBase o) =>\n    o is UniformIntOption or UniformSingleOption or UniformDoubleOption;","tryCatchPattern":"try { JsonSerializer.Serialize(writer, value, options); }\ncatch (ArgumentException ex) when (ex.Message == \"unknown type\")\n{\n    // convert the derived option to a base Uniform*Option and retry\n}","preventionTips":["Avoid custom subclasses of numeric options in serialized search spaces.","Keep serializer and ML.NET package versions aligned.","Test round-trip (serialize→deserialize) of every search space in CI."],"tags":["json","serialization","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"}