{"record":{"id":"618625d6830ee76f","repo":"dotnet/machinelearning","slug":"the-trainer-trainer-is-not-handled-currently","errorCode":null,"errorMessage":"The trainer '{trainer}' is not handled currently.","messagePattern":"The trainer '(.+?)' is not handled currently\\.","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.ML.CodeGenerator/CodeGenerator/CSharp/TrainerGeneratorFactory.cs","lineNumber":77,"sourceCode":"                        return new StochasticDualCoordinateAscentMulti(node);\n                    case TrainerName.SdcaRegression:\n                        return new StochasticDualCoordinateAscentRegression(node);\n                    case TrainerName.SgdCalibratedBinary:\n                        return new SgdCalibratedBinary(node);\n                    case TrainerName.SymbolicSgdLogisticRegressionBinary:\n                        return new SymbolicSgdLogisticRegressionBinary(node);\n                    case TrainerName.Ova:\n                        return new OneVersusAll(node);\n                    case TrainerName.ImageClassification:\n                        return new ImageClassificationTrainer(node);\n                    case TrainerName.MatrixFactorization:\n                        return new MatrixFactorization(node);\n                    case TrainerName.LightGbmRanking:\n                        return new LightGbmRanking(node);\n                    case TrainerName.FastTreeRanking:\n                        return new FastTreeRanking(node);\n                    default:\n                        throw new ArgumentException($\"The trainer '{trainer}' is not handled currently.\");\n                }\n            }\n            throw new ArgumentException($\"The trainer '{node.Name}' is not handled currently.\");\n        }\n    }\n}\n","sourceCodeStart":59,"sourceCodeEnd":84,"githubUrl":"https://github.com/dotnet/machinelearning/blob/7b76e69cf964daeca3f1377af6bc5543284d56c6/src/Microsoft.ML.CodeGenerator/CodeGenerator/CSharp/TrainerGeneratorFactory.cs#L59-L84","documentation":"TrainerGeneratorFactory.GetInstance parses the AutoML PipelineNode name into the TrainerName enum and maps recognized trainers to C# code-generator classes. When the parsed trainer name is a valid TrainerName member but has no case in the switch, the default branch throws this ArgumentException. It means the code generator does not yet support emitting C# for that trainer.","triggerScenarios":"Calling TrainerGeneratorFactory.GetInstance with a PipelineNode whose Name parses to a TrainerName that exists in the enum but is not one of the ~25 cases handled in the switch (e.g. a newly added AutoML trainer like a new LightGbm variant or HgBoosting) while running ML.NET AutoML-to-C# code generation.","commonSituations":"Developers using Microsoft.ML.CodeGenerator (mlnet CLI / AutoML 'convert to C#' flow) on a model whose best pipeline picked a trainer that the generator hasn't implemented; version skew where Microsoft.ML.AutoML gained trainers the CodeGenerator package doesn't know yet.","solutions":["Check the trainer name in the message against the switch in TrainerGeneratorFactory.GetInstance; pick a different trainer in your AutoML experiment (exclude unsupported ones via trainers parameter/exclusion list).","Upgrade Microsoft.ML.CodeGenerator (and mlnet CLI) to the latest version, which may add a case for this trainer.","If you own the code, add a case mapping the TrainerName to a new ITrainerGenerator implementation.","Handle the generated pipeline manually: inspect the AutoML pipeline and write the trainer C# code yourself."],"exampleFix":"// before: AutoML experiment allowed all trainers\nvar experiment = mlContext.Auto().CreateBinaryClassificationExperiment();\n// after: restrict to trainers the code generator supports\nvar experiment = mlContext.Auto().CreateBinaryClassificationExperiment(\n    experimentSettings => experimentSettings.UseFractions(...));\n// or exclude unsupported trainers via TrainPersonalityAndTrainer exclusion in pipeline sweeps","handlingStrategy":"try-catch","validationCode":"if (!Enum.TryParse<TrainerName>(node.Name, out var t) ||\n    !typeof(TrainerGeneratorFactory).Assembly.GetTypes().Any()) { /* precheck supported set */ }\nvar supported = new HashSet<string>(new[]{\"LightGbmBinary\",\"LightGbmMulti\",\"LightGbmRegression\",\"FastTreeBinary\",\"FastTreeRegression\",\"SdcaLogisticRegressionBinary\",\"LbfgsLogisticRegressionBinary\"});\nbool canGenerate = supported.Contains(node.Name);","typeGuard":"static bool IsSupportedTrainer(string name) =>\n    Enum.TryParse<TrainerName>(name, out var t) &&\n    Enum.IsDefined(typeof(TrainerName), t) &&\n    SupportedTrainers.Contains(t);","tryCatchPattern":"try\n{\n    var gen = TrainerGeneratorFactory.GetInstance(node);\n}\ncatch (ArgumentException ex) when (ex.Message.Contains(\"is not handled currently\"))\n{\n    Console.WriteLine($\"Skipping trainer {node.Name}: code generation unsupported\");\n}","preventionTips":["Restrict AutoML sweeps to trainers known to be supported by the code generator.","Keep Microsoft.ML.CodeGenerator and Microsoft.ML.AutoML package versions in sync.","Pre-check the trainer name against the factory's switch before invoking codegen.","Log unsupported trainers instead of failing the whole conversion."],"tags":["codegen","mlnet","unsupported-trainer","argument-exception"],"backgroundTag":"unsupported-operation","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"}