dotnet/machinelearning · error · ArgumentException

File at path '{path}' cannot be empty

Error message

File at path '{path}' cannot be empty

What it means

ML.NET AutoML validates user-supplied file paths before running an experiment. This ArgumentException is thrown by ValidatePath when the file at the given path exists but has a length of 0 bytes. AutoML refuses empty files because training/inference on an empty dataset is meaningless.

Source

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

        }

        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));
            }

            const string schemaMismatchError = "Training data and validation data schemas do not match.";

            if (trainData.Schema.Count(c => !c.IsHidden) != validationData.Schema.Count(c => !c.IsHidden))

View on GitHub (pinned to 7b76e69cf9)

Solutions

  1. Verify the file has content: check `new FileInfo(path).Length > 0` before calling the API.
  2. Fix the upstream producer so the file is fully written (atomic write, then rename).
  3. Re-download or regenerate the dataset.
  4. Point to the correct file — you may be looking at a placeholder with the same name.

Example fix

// before
await client.DownloadFileTaskAsync(url, "data.csv"); // may leave empty file on failure
// after
await client.DownloadFileTaskAsync(url, "data.tmp");
if (new FileInfo("data.tmp").Length == 0) throw new IOException("download produced empty file");
File.Move("data.tmp", "data.csv");
Defensive patterns

Strategy: validation

Validate before calling

var fi = new FileInfo(path);
if (!fi.Exists) throw new FileNotFoundException(path);
if (fi.Length == 0) throw new ArgumentException($"File '{path}' is empty");

Try / catch

try { automlResult = experiment.Execute(trainDataPath, ...); }
catch (ArgumentException ex) when (ex.ParamName == "path") { /* surface empty-file guidance */ }

Prevention

When it happens

Trigger: Calling any AutoML API that resolves to ValidateInferColumnsArgs (e.g. InferColumns or Experiment API) with a path to a file that exists but contains 0 bytes — e.g. the file was truncated by a failed download, created by a crashed pipeline, or touched by a script before content was written.

Common situations: Downloaded CSV interrupted mid-write; output redirection creating an empty file; upstream ETL job produced an empty extract; pointing at a file created by `touch` or a logger that never flushed.

Understand the failure class

Background: "must not be empty", "cannot be empty" — required-field validation errors across open-source libraries — this error's family across 41 libraries.

Related errors


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