dotnet/machinelearning · error · ArgumentException

File '{path}' does not exist

Error message

File '{path}' does not exist

What it means

Thrown by UserInputValidationUtil.ValidatePath when the supplied file path is non-null but no file exists at that location on disk. ValidatePath constructs a FileInfo and requires Exists; the message includes the offending path so the developer can correct it.

Source

Thrown at src/Microsoft.ML.AutoML/Utils/UserInputValidationUtil.cs:175

        {
            if (labelColumn == null)
            {
                throw new ArgumentException("Provided label column cannot be null");
            }
        }

        private static void ValidatePath(string path)
        {
            if (path == null)
            {
                throw new ArgumentNullException(nameof(path), "Provided path cannot be null");
            }

            var fileInfo = new FileInfo(path);

            if (!fileInfo.Exists)
            {
                throw new ArgumentException($"File '{path}' does not exist", nameof(path));
            }

            if (fileInfo.Length == 0)
            {
                throw new ArgumentException($"File at path '{path}' cannot be empty", nameof(path));
            }
        }

        private static void ValidateValidationData(IDataView trainData, IDataView validationData)
        {
            if (validationData == null)
            {
                return;
            }

            if (DatasetDimensionsUtil.IsDataViewEmpty(validationData))
            {
                throw new ArgumentException("Validation data has 0 rows", nameof(validationData));

View on GitHub (pinned to 7b76e69cf9)

Solutions

  1. Verify the file exists with File.Exists(path) before calling and correct the path
  2. Use absolute paths built with Path.Combine(AppContext.BaseDirectory, ...) instead of bare relative names
  3. Ensure the data file is included in build/deployment output (Copy to Output Directory)

Example fix

// before
var columns = mlContext.Auto().InferColumns("train.csv", labelColumnName: "Label"); // not found when run from bin dir

// after
string dataPath = Path.Combine(AppContext.BaseDirectory, "train.csv");
if (!File.Exists(dataPath)) throw new FileNotFoundException("Training data missing", dataPath);
var columns = mlContext.Auto().InferColumns(dataPath, labelColumnName: "Label");
Defensive patterns

Strategy: validation

Validate before calling

if (!File.Exists(path)) throw new FileNotFoundException($"Data file not found: {path}", path);

Try / catch

try { var cols = mlContext.Auto().InferColumns(path, labelColumnName); }
catch (ArgumentException ex) when (ex.Message.Contains("does not exist")) { /* log resolved absolute path and correct config */ }

Prevention

When it happens

Trigger: Calling AutoML InferColumns with a path to a missing file: typo in filename, wrong working directory with a relative path, file deleted/moved between runs.

Common situations: Relative paths that resolve differently when running from bin/Debug vs project root; case-sensitive file systems in Linux containers; deployment package not copying the data file; Windows/Linux path separator mistakes.

Understand the failure class

Background: "File not found" and ENOENT errors: why libraries can't find a file that should exist — this error's family across 50 libraries.

Related errors


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