dotnet/machinelearning · error · ArgumentException

The trainer '{node.Name}' is not handled currently.

Error message

The trainer '{node.Name}' is not handled currently.

What it means

The second throw in TrainerGeneratorFactory.GetInstance: reached when Enum.TryParse(node.Name) fails, i.e. the pipeline node's trainer name is not even a member of the TrainerName enum. The factory therefore cannot map the node to any C# trainer generator and throws this ArgumentException with the raw node name in the message.

Source

Thrown at src/Microsoft.ML.CodeGenerator/CodeGenerator/CSharp/TrainerGeneratorFactory.cs:80

                    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

  1. Compare node.Name in the message to members of the Microsoft.ML.AutoML.TrainerName enum and fix the pipeline node to use the exact enum member name.
  2. Verify the CodeGenerator and AutoML package versions match; align NuGet package versions.
  3. Add the trainer to the TrainerName enum and the factory switch if you control the source.
  4. Wrap GetInstance in a try-catch and fall back to a manual/echo pipeline when the trainer is unknown.

Example fix

// before
var node = new PipelineNode { Name = "LightGbm" };
// after
var node = new PipelineNode { Name = "LightGbmBinary" }; // exact TrainerName enum member
Defensive patterns

Strategy: validation

Validate before calling

if (string.IsNullOrWhiteSpace(node.Name) ||
    !Enum.TryParse<TrainerName>(node.Name, out _))
    throw new InvalidOperationException($"Unknown trainer name: '{node.Name}'");

Type guard

static bool IsValidTrainerName(string name) =>
    !string.IsNullOrEmpty(name) &&
    Enum.IsDefined(typeof(TrainerName), name) && // parses via TryParse semantics
    Enum.TryParse(name, out TrainerName _);

Try / catch

try
{
    return TrainerGeneratorFactory.GetInstance(node);
}
catch (ArgumentException ex) when (ex.Message.Contains("not handled currently"))
{
    return null; // fall back to manual handling
}

Prevention

When it happens

Trigger: Calling GetInstance with a PipelineNode whose Name string is misspelled, empty, or from a different ML.NET version than the TrainerName enum compiled into the CodeGenerator assembly (e.g. 'LightGbm' vs 'LightGbmBinary').

Common situations: Hand-built PipelineNode instances fed into the code generator; name drift after upgrading Microsoft.ML.AutoML so TrainerName members were renamed; custom pipelines serialized with legacy trainer names.

Understand the failure class

Background: Invalid enum value errors: "Unknown type", "Invalid scope", "must be one of" — when a string is not on the library's allowed list — this error's family across 23 libraries.

Related errors


AI-assisted analysis of dotnet/machinelearning@7b76e69cf9 (2026-09-11). Data as JSON: /api/errors/d824ed79f39e95e7. Report an issue: GitHub.