dotnet/machinelearning · error · ArgumentException
The trainer '{trainer}' is not handled currently.
Error message
The trainer '{trainer}' is not handled currently. What it means
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.
Source
Thrown at src/Microsoft.ML.CodeGenerator/CodeGenerator/CSharp/TrainerGeneratorFactory.cs:77
return new StochasticDualCoordinateAscentMulti(node);
case TrainerName.SdcaRegression:
return new StochasticDualCoordinateAscentRegression(node);
case TrainerName.SgdCalibratedBinary:
return new SgdCalibratedBinary(node);
case TrainerName.SymbolicSgdLogisticRegressionBinary:
return new SymbolicSgdLogisticRegressionBinary(node);
case TrainerName.Ova:
return new OneVersusAll(node);
case TrainerName.ImageClassification:
return new ImageClassificationTrainer(node);
case TrainerName.MatrixFactorization:
return new MatrixFactorization(node);
case TrainerName.LightGbmRanking:
return new LightGbmRanking(node);
case TrainerName.FastTreeRanking:
return new FastTreeRanking(node);
default:
throw new ArgumentException($"The trainer '{trainer}' is not handled currently.");
}
}
throw new ArgumentException($"The trainer '{node.Name}' is not handled currently.");
}
}
}
View on GitHub (pinned to 7b76e69cf9)
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.
Example fix
// before: AutoML experiment allowed all trainers
var experiment = mlContext.Auto().CreateBinaryClassificationExperiment();
// after: restrict to trainers the code generator supports
var experiment = mlContext.Auto().CreateBinaryClassificationExperiment(
experimentSettings => experimentSettings.UseFractions(...));
// or exclude unsupported trainers via TrainPersonalityAndTrainer exclusion in pipeline sweeps Defensive patterns
Strategy: try-catch
Validate before calling
if (!Enum.TryParse<TrainerName>(node.Name, out var t) ||
!typeof(TrainerGeneratorFactory).Assembly.GetTypes().Any()) { /* precheck supported set */ }
var supported = new HashSet<string>(new[]{"LightGbmBinary","LightGbmMulti","LightGbmRegression","FastTreeBinary","FastTreeRegression","SdcaLogisticRegressionBinary","LbfgsLogisticRegressionBinary"});
bool canGenerate = supported.Contains(node.Name); Type guard
static bool IsSupportedTrainer(string name) =>
Enum.TryParse<TrainerName>(name, out var t) &&
Enum.IsDefined(typeof(TrainerName), t) &&
SupportedTrainers.Contains(t); Try / catch
try
{
var gen = TrainerGeneratorFactory.GetInstance(node);
}
catch (ArgumentException ex) when (ex.Message.Contains("is not handled currently"))
{
Console.WriteLine($"Skipping trainer {node.Name}: code generation unsupported");
} Prevention
- 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.
When it happens
Trigger: 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.
Common situations: 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.
Understand the failure class
Background: UnsupportedOperationException and "is not supported" errors: when a library deliberately refuses a call — this error's family across 30 libraries.
Related errors
- The trainer '{node.Name}' is not handled currently.
- The data type '{labelType}' is not handled currently.
- The data type '{dataKind}' is not handled currently.
- Type IPredictionTransformer not implemented by provided type
- Value name '{0}' matches an existing column name
AI-assisted analysis of dotnet/machinelearning@7b76e69cf9 (2026-09-11).
Data as JSON: /api/errors/618625d6830ee76f.
Report an issue: GitHub.