dotnet/machinelearning · error · NotImplementedException
{metric} is not supported!
Error message
{metric} is not supported! What it means
GetMetric in BinaryClassificationExperiment maps a BinaryClassificationMetric enum value to the corresponding field of the evaluated metrics. Any enum value not explicitly listed in the switch (e.g. Accuracy) falls into the default arm and throws NotImplementedException. It means the caller requested a metric this experiment's mapping does not support.
Source
Thrown at src/Microsoft.ML.AutoML/API/BinaryClassificationExperiment.cs:482
catch (Exception)
{
throw;
}
}
private double GetMetric(BinaryClassificationMetric metric, BinaryClassificationMetrics metrics)
{
return metric switch
{
BinaryClassificationMetric.PositivePrecision => metrics.PositivePrecision,
BinaryClassificationMetric.Accuracy => metrics.Accuracy,
BinaryClassificationMetric.AreaUnderRocCurve => metrics.AreaUnderRocCurve,
BinaryClassificationMetric.AreaUnderPrecisionRecallCurve => metrics.AreaUnderPrecisionRecallCurve,
BinaryClassificationMetric.PositiveRecall => metrics.PositiveRecall,
BinaryClassificationMetric.NegativePrecision => metrics.NegativePrecision,
BinaryClassificationMetric.NegativeRecall => metrics.NegativeRecall,
BinaryClassificationMetric.F1Score => metrics.F1Score,
_ => throw new NotImplementedException($"{metric} is not supported!"),
};
}
}
}
View on GitHub (pinned to 7b76e69cf9)
Solutions
- Use only the metrics the switch supports: AreaUnderRocCurve, AreaUnderPrecisionRecallCurve, PositiveRecall, NegativePrecision, F1Score (and check the enum definition for Accuracy, which may be supported elsewhere in the pipeline).
- Validate the configured metric against the supported set before starting the experiment.
- If a new enum member must be supported, add an arm to the switch in BinaryClassificationExperiment.GetMetric and file/accept an upstream patch.
Example fix
// before
var metric = BinaryClassificationMetric.Accuracy;
var value = GetMetric(metric); // throws NotImplementedException
// after
var supported = new[] { BinaryClassificationMetric.AreaUnderRocCurve, BinaryClassificationMetric.F1Score };
var metric = supported.Contains(requested) ? requested : BinaryClassificationMetric.AreaUnderRocCurve; Defensive patterns
Strategy: validation
Validate before calling
private static readonly BinaryClassificationMetric[] SupportedMetrics =
{
BinaryClassificationMetric.AreaUnderRocCurve,
BinaryClassificationMetric.AreaUnderPrecisionRecallCurve,
BinaryClassificationMetric.PositiveRecall,
BinaryClassificationMetric.NegativePrecision,
BinaryClassificationMetric.NegativeRecall,
BinaryClassificationMetric.F1Score
};
// before running:
if (!SupportedMetrics.Contains(metric)) throw new ArgumentException($"Metric {metric} not supported by this experiment"); Type guard
bool IsSupported(BinaryClassificationMetric m) => m is BinaryClassificationMetric.AreaUnderRocCurve or BinaryClassificationMetric.AreaUnderPrecisionRecallCurve or BinaryClassificationMetric.PositiveRecall or BinaryClassificationMetric.NegativePrecision or BinaryClassificationMetric.NegativeRecall or BinaryClassificationMetric.F1Score;
Try / catch
try { var value = GetMetric(metric); }
catch (NotImplementedException) { // fall back to AreaUnderRocCurve or surface config error
metric = BinaryClassificationMetric.AreaUnderRocCurve; } Prevention
- Keep a whitelist of supported metrics next to the experiment configuration
- Validate user-supplied metric strings against the enum subset before starting the run
- Re-check the supported set after upgrading Microsoft.ML.AutoML versions
When it happens
Trigger: Calling code that resolves a BinaryClassificationMetric through this experiment's GetMetric with an enum member not present in the switch arms (AreaUnderRocCurve, AreaUnderPrecisionRecallCurve, PositiveRecall, NegativePrecision, NegativeRecall, F1Score), e.g. BinaryClassificationMetric.Accuracy.
Common situations: Passing a metric enum value that is valid elsewhere in ML.NET but not wired into this AutoML experiment's mapping; library version drift where new enum members were added but the switch was not updated; user-supplied metric configuration strings converted into enum values without whitelisting.
Related errors
- {metric} is not supported!
- {metric} is not supported!
- joinAlgorithm
- {fieldType.Name}
- The method or operation is not implemented.
AI-assisted analysis of dotnet/machinelearning@7b76e69cf9 (2026-09-11).
Data as JSON: /api/errors/a297e58c73465371.
Report an issue: GitHub.