dotnet/machinelearning · warning · OperationCanceledException
OperationCanceledException
Error message
OperationCanceledException
What it means
SweepablePipelineRunner.RunAsync wraps trial execution; when the cancellation token is requested and the trial body throws, it rethrows as OperationCanceledException to signal cooperative cancellation. The message is the inner exception's message (or generic), so the real failure cause is preserved as the inner exception. This is the standard .NET cancellation-propagation pattern.
Source
Thrown at src/Microsoft.ML.AutoML/AutoMLExperiment/Runner/SweepablePipelineRunner.cs:108
throw new ArgumentException("IDatasetManager must be either ITrainTestDatasetManager or ICrossValidationDatasetManager");
}
public Task<TrialResult> RunAsync(TrialSettings settings, CancellationToken ct)
{
try
{
using (var ctRegistration = ct.Register(() =>
{
_mLContext?.CancelExecution();
}))
{
return Task.FromResult(Run(settings));
}
}
catch (Exception ex) when (ct.IsCancellationRequested)
{
throw new OperationCanceledException(ex.Message, ex.InnerException);
}
catch (Exception)
{
throw;
}
}
public void Dispose()
{
_mLContext!.CancelExecution();
_mLContext = null;
}
}
}
View on GitHub (pinned to 7b76e69cf9)
Solutions
- Inspect ex.InnerException to find the underlying failure if cancellation was not intended
- Check ct.IsCancellationRequested to confirm cancellation was expected; if so, treat as normal stop
- Avoid cancelling the token before trials complete, or drain running trials gracefully
- If a genuine training error was masked, rerun without cancelling to surface the real exception
Example fix
// before
try { var r = await runner.RunAsync(settings, ct); }
catch (Exception e) { Log.Error(e.Message); }
// after
try { var r = await runner.RunAsync(settings, ct); }
catch (OperationCanceledException) when (ct.IsCancellationRequested) { Log.Info("Trial cancelled"); }
catch (Exception e) { Log.Error(e.InnerException?.Message ?? e.Message); } Defensive patterns
Strategy: try-catch
Validate before calling
if (ct.IsCancellationRequested) return; // don't start trials already cancelled
Try / catch
try { var r = await runner.RunAsync(settings, ct); }
catch (OperationCanceledException oce) when (ct.IsCancellationRequested)
{
// expected cancellation; inspect oce.InnerException for masked errors
} Prevention
- Always catch OperationCanceledException separately from general exceptions
- Inspect InnerException for the true root cause
- Pass linked cancellation tokens deliberately and log cancellations
When it happens
Trigger: The CancellationToken passed to RunAsync is cancelled (experiment stop/timeout) while Run(settings) or trial evaluation is in progress and throws; the catch filter `when (ct.IsCancellationRequested)` routes any exception into OperationCanceledException.
Common situations: Cancelling an AutoML experiment via its cancellation token or a timeout; host shutting down mid-trial; an underlying ML.NET failure occurring at the same moment cancellation was requested (masking the true error).
Understand the failure class
Background: Request timed out: what client-side request timeouts mean across libraries (Request timed out, TIMED_OUT, APITimeoutError) — this error's family across 39 libraries.
Related errors
- can't add or update result that already save to csv
- IDatasetManager must be either ITrainTestDatasetManager or I
- Unable to split the file provided into multiple, consistent
- Unable to infer column types of the file provided.
- Specified column {columnName} is not found in the dataset.
AI-assisted analysis of dotnet/machinelearning@7b76e69cf9 (2026-09-11).
Data as JSON: /api/errors/0a4205a962b51bd1.
Report an issue: GitHub.