dotnet/machinelearning · error · ArgumentException

The runner metric manager is of type {_metricManager.GetType

Error message

The runner metric manager is of type {_metricManager.GetType()} which expected to be of type {typeof(ITrainValidateDatasetManager)} or {typeof(ICrossValidateDatasetManager)}

What it means

RegressionExperiment.RunAsync's evaluation loop dispatches on the type of _metricManager and only handles ITrainValidateDatasetManager and ICrossValidateDatasetManager. When the manager is another type, neither branch produces a TrialResult and control reaches the trailing throw of ArgumentException, indicating a misconfigured runner.

Source

Thrown at src/Microsoft.ML.AutoML/API/RegressionExperiment.cs:450

                            var loss = metricManager.IsMaximize ? -metric : metric;

                            stopWatch.Stop();


                            return Task.FromResult(new TrialResult<RegressionMetrics>()
                            {
                                Loss = loss,
                                Metric = metric,
                                Metrics = metrics,
                                Model = model,
                                TrialSettings = settings,
                                DurationInMilliseconds = stopWatch.ElapsedMilliseconds,
                                Pipeline = refitPipeline,
                            } as TrialResult);
                        }
                    }

                    throw new ArgumentException($"The runner metric manager is of type {_metricManager.GetType()} which expected to be of type {typeof(ITrainValidateDatasetManager)} or {typeof(ICrossValidateDatasetManager)}");
                }
            }
            catch (Exception ex) when (ct.IsCancellationRequested)
            {
                throw new OperationCanceledException(ex.Message, ex.InnerException);
            }
            catch (Exception)
            {
                throw;
            }
        }

        public void Dispose()
        {
            _context.CancelExecution();
            _context = null;
        }

View on GitHub (pinned to 7b76e69cf9)

Solutions

  1. Construct the experiment through the standard builders so a TrainTestSplit (ITrainValidateDatasetManager) or CrossValidation (ICrossValidateDatasetManager) manager is used.
  2. Make custom dataset managers implement one of the two expected interfaces.
  3. Validate the manager type at experiment setup and throw early with a descriptive message.
  4. Align all Microsoft.ML.AutoML package references to the same version.

Example fix

// before
experiment.SetDataset(new MyDatasetManager(data)); // unsupported type
await experiment.RunAsync(ct);
// after
experiment.SetDataset(new CrossValidationDatasetManager(data, numFolds: 5));
await experiment.RunAsync(ct);
Defensive patterns

Strategy: type-guard

Validate before calling

// before RunAsync:
if (_metricManager is not ITrainValidateDatasetManager and not ICrossValidateDatasetManager)
    throw new InvalidOperationException("Use TrainTestSplit or CrossValidation dataset manager");

Type guard

bool IsValidManager(object m) => m is ITrainValidateDatasetManager or ICrossValidateDatasetManager;

Try / catch

try { var best = await experiment.RunAsync(ct); }
catch (ArgumentException ex) when (ex.Message.Contains("metric manager")) { // rebuild experiment with standard dataset manager
    throw new InvalidOperationException("Regression experiment dataset manager misconfigured", ex); }

Prevention

When it happens

Trigger: Running a regression AutoML experiment whose metric/dataset manager object is neither ITrainValidateDatasetManager nor ICrossValidateDatasetManager (custom implementation or wrong object injected), so both switch branches are skipped and the terminal ArgumentException is hit.

Common situations: Hand-rolled AutoML runners; dependency-injection misconfiguration supplying a custom IDatasetManager; package version mismatch where runner interfaces were refactored.

Understand the failure class

Background: Type mismatch errors: IllegalArgumentException, TypeError and type guards across 150 open-source libraries — this error's family across 150 libraries.

Related errors


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