{"record":{"id":"a297e58c73465371","repo":"dotnet/machinelearning","slug":"metric-is-not-supported","errorCode":null,"errorMessage":"{metric} is not supported!","messagePattern":"(.+?) is not supported!","errorType":"exception","errorClass":"NotImplementedException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.ML.AutoML/API/BinaryClassificationExperiment.cs","lineNumber":482,"sourceCode":"            catch (Exception)\n            {\n                throw;\n            }\n        }\n\n        private double GetMetric(BinaryClassificationMetric metric, BinaryClassificationMetrics metrics)\n        {\n            return metric switch\n            {\n                BinaryClassificationMetric.PositivePrecision => metrics.PositivePrecision,\n                BinaryClassificationMetric.Accuracy => metrics.Accuracy,\n                BinaryClassificationMetric.AreaUnderRocCurve => metrics.AreaUnderRocCurve,\n                BinaryClassificationMetric.AreaUnderPrecisionRecallCurve => metrics.AreaUnderPrecisionRecallCurve,\n                BinaryClassificationMetric.PositiveRecall => metrics.PositiveRecall,\n                BinaryClassificationMetric.NegativePrecision => metrics.NegativePrecision,\n                BinaryClassificationMetric.NegativeRecall => metrics.NegativeRecall,\n                BinaryClassificationMetric.F1Score => metrics.F1Score,\n                _ => throw new NotImplementedException($\"{metric} is not supported!\"),\n            };\n        }\n    }\n}\n","sourceCodeStart":464,"sourceCodeEnd":487,"githubUrl":"https://github.com/dotnet/machinelearning/blob/7b76e69cf964daeca3f1377af6bc5543284d56c6/src/Microsoft.ML.AutoML/API/BinaryClassificationExperiment.cs#L464-L487","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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."],"exampleFix":"// before\nvar metric = BinaryClassificationMetric.Accuracy;\nvar value = GetMetric(metric); // throws NotImplementedException\n// after\nvar supported = new[] { BinaryClassificationMetric.AreaUnderRocCurve, BinaryClassificationMetric.F1Score };\nvar metric = supported.Contains(requested) ? requested : BinaryClassificationMetric.AreaUnderRocCurve;","handlingStrategy":"validation","validationCode":"private static readonly BinaryClassificationMetric[] SupportedMetrics =\n{\n    BinaryClassificationMetric.AreaUnderRocCurve,\n    BinaryClassificationMetric.AreaUnderPrecisionRecallCurve,\n    BinaryClassificationMetric.PositiveRecall,\n    BinaryClassificationMetric.NegativePrecision,\n    BinaryClassificationMetric.NegativeRecall,\n    BinaryClassificationMetric.F1Score\n};\n// before running:\nif (!SupportedMetrics.Contains(metric)) throw new ArgumentException($\"Metric {metric} not supported by this experiment\");","typeGuard":"bool IsSupported(BinaryClassificationMetric m) => m is BinaryClassificationMetric.AreaUnderRocCurve or BinaryClassificationMetric.AreaUnderPrecisionRecallCurve or BinaryClassificationMetric.PositiveRecall or BinaryClassificationMetric.NegativePrecision or BinaryClassificationMetric.NegativeRecall or BinaryClassificationMetric.F1Score;","tryCatchPattern":"try { var value = GetMetric(metric); }\ncatch (NotImplementedException) { // fall back to AreaUnderRocCurve or surface config error\n    metric = BinaryClassificationMetric.AreaUnderRocCurve; }","preventionTips":["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"],"tags":["not-implemented","enum","metric","automl"],"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"}