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

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.

Source

Thrown at src/Microsoft.ML.AutoML/API/MulticlassClassificationExperiment.cs:423

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

                    stopWatch.Stop();


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

            throw new ArgumentException($"The runner metric manager is of type {_metricManager.GetType()} which expected to be of type {typeof(ITrainValidateDatasetManager)} or {typeof(ICrossValidateDatasetManager)}");
        }

        public Task<TrialResult> RunAsync(TrialSettings settings, CancellationToken ct)
        {
            try
            {
                using (var ctRegistration = ct.Register(() =>
                {
                    _context?.CancelExecution();
                }))
                {
                    return Task.FromResult(Run(settings));
                }
            }
            catch (Exception ex) when (ct.IsCancellationRequested)
            {
                throw new OperationCanceledException(ex.Message, ex.InnerException);
            }

View on GitHub (pinned to 7b76e69cf9)

Solutions

  1. Use the standard experiment construction path (AutoMLExperiment with TrainTestSplit or CrossValidation settings) so the correct ITrainValidateDatasetManager/ICrossValidateDatasetManager is created.
  2. Make any custom dataset manager implement ITrainValidateDatasetManager or ICrossValidateDatasetManager.
  3. Add an upfront type check (pattern matching) on _metricManager and fail fast with a clearer message.
  4. Verify the ML.NET/AutoML package versions of all referenced assemblies match to avoid type identity mismatches.

Example fix

// before
experiment.SetDataset(myCustomDatasetManager); // neither ITrainValidateDatasetManager nor ICrossValidateDatasetManager
await experiment.RunAsync();
// after
var datasetManager = new CrossValidationDatasetManager(trainData, 5);
experiment.SetDataset(datasetManager); // implements ICrossValidateDatasetManager
Defensive patterns

Strategy: type-guard

Validate before calling

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

Type guard

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

Try / catch

try { await experiment.RunAsync(ct); }
catch (ArgumentException ex) when (ex.Message.Contains("metric manager")) { // reconfigure the experiment with a standard dataset manager
    throw new InvalidOperationException("Experiment misconfigured: dataset manager type unsupported", ex); }

Prevention

When it happens

Trigger: 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.

Common situations: 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.

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/f9f9dc8561f0e985. Report an issue: GitHub.