{"record":{"id":"f9f9dc8561f0e985","repo":"dotnet/machinelearning","slug":"the-runner-metric-manager-is-of-type-metricmanag-f9f9dc","errorCode":null,"errorMessage":"The runner metric manager is of type {_metricManager.GetType()} which expected to be of type {typeof(ITrainValidateDatasetManager)} or {typeof(ICrossValidateDatasetManager)}","messagePattern":"The runner metric manager is of type (.+?) which expected to be of type (.+?) or (.+?)","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.ML.AutoML/API/MulticlassClassificationExperiment.cs","lineNumber":423,"sourceCode":"                    var loss = metricManager.IsMaximize ? -metric : metric;\n\n                    stopWatch.Stop();\n\n\n                    return new TrialResult<MulticlassClassificationMetrics>()\n                    {\n                        Loss = loss,\n                        Metric = metric,\n                        Model = model,\n                        TrialSettings = settings,\n                        DurationInMilliseconds = stopWatch.ElapsedMilliseconds,\n                        Metrics = metrics,\n                        Pipeline = refitPipeline,\n                    };\n                }\n            }\n\n            throw new ArgumentException($\"The runner metric manager is of type {_metricManager.GetType()} which expected to be of type {typeof(ITrainValidateDatasetManager)} or {typeof(ICrossValidateDatasetManager)}\");\n        }\n\n        public Task<TrialResult> RunAsync(TrialSettings settings, CancellationToken ct)\n        {\n            try\n            {\n                using (var ctRegistration = ct.Register(() =>\n                {\n                    _context?.CancelExecution();\n                }))\n                {\n                    return Task.FromResult(Run(settings));\n                }\n            }\n            catch (Exception ex) when (ct.IsCancellationRequested)\n            {\n                throw new OperationCanceledException(ex.Message, ex.InnerException);\n            }","sourceCodeStart":405,"sourceCodeEnd":441,"githubUrl":"https://github.com/dotnet/machinelearning/blob/7b76e69cf964daeca3f1377af6bc5543284d56c6/src/Microsoft.ML.AutoML/API/MulticlassClassificationExperiment.cs#L405-L441","documentation":"MulticlassClassificationExperiment.Run dispatches evaluation based on the type of _metricManager, which must be either ITrainValidateDatasetManager or ICrossValidateDatasetManager. If the injected dataset manager is any other type, the run pipeline completes its branches without producing results and throws ArgumentException. It signals an internally inconsistent runner configuration.","triggerScenarios":"Running a multiclass AutoML experiment (RunAsync -> Run) where the IDatasetManager/MetricManager supplied to the experiment runner is a custom or wrong-typed implementation that implements neither ITrainValidateDatasetManager nor ICrossValidateDatasetManager.","commonSituations":"Custom AutoML runner/dataset-manager implementations plugged into the experiment; internal wiring bugs after library upgrades; constructing experiment components manually instead of through the standard experiment builders.","solutions":["Use the standard experiment construction path (AutoMLExperiment with TrainTestSplit or CrossValidation settings) so the correct ITrainValidateDatasetManager/ICrossValidateDatasetManager is created.","Make any custom dataset manager implement ITrainValidateDatasetManager or ICrossValidateDatasetManager.","Add an upfront type check (pattern matching) on _metricManager and fail fast with a clearer message.","Verify the ML.NET/AutoML package versions of all referenced assemblies match to avoid type identity mismatches."],"exampleFix":"// before\nexperiment.SetDataset(myCustomDatasetManager); // neither ITrainValidateDatasetManager nor ICrossValidateDatasetManager\nawait experiment.RunAsync();\n// after\nvar datasetManager = new CrossValidationDatasetManager(trainData, 5);\nexperiment.SetDataset(datasetManager); // implements ICrossValidateDatasetManager","handlingStrategy":"type-guard","validationCode":"// before RunAsync:\nif (_metricManager is not ITrainValidateDatasetManager and not ICrossValidateDatasetManager)\n    throw new InvalidOperationException(\"Configure TrainTestSplit or CrossValidation before running\");","typeGuard":"bool IsValidManager(object m) => m is ITrainValidateDatasetManager or ICrossValidateDatasetManager;","tryCatchPattern":"try { await experiment.RunAsync(ct); }\ncatch (ArgumentException ex) when (ex.Message.Contains(\"metric manager\")) { // reconfigure the experiment with a standard dataset manager\n    throw new InvalidOperationException(\"Experiment misconfigured: dataset manager type unsupported\", ex); }","preventionTips":["Always configure the dataset via TrainTestSplit or CrossValidation helpers instead of custom managers","Unit-test experiment construction in DI setups","Keep all Microsoft.ML.* package versions aligned"],"tags":["argument-exception","type-mismatch","automl","runner"],"backgroundTag":"type-mismatch","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"}