dotnet/machinelearning · critical · ArgumentException
The provided model file
Error message
The provided model file {filePath} doesn't exist. What it means
FileModelLoader.Start loads an ML.NET model from a file path and throws ArgumentException when the file does not exist at the given path. The loader needs a real file to watch and load (including for reload polling), so it fails fast before setting up watchers. The message includes the offending path to make the misconfiguration obvious.
Solutions
- Verify the file exists at the exact path passed to Start: use an absolute path or check File.Exists first.
- Fix relative-path resolution — confirm the process's current working directory and anchor the path with Path.Combine(AppContext.BaseDirectory, ...) or an absolute config value.
- Ensure the model file is deployed/copied into the container or output directory (set Copy to Output Directory, or bake it into the image).
- If the model is produced by a training job, verify that job succeeded and wrote to the expected location before starting the app.
Example fix
// before
var loader = new FileModelLoader(_logger, "models/model.zip");
loader.Start(); // ArgumentException if CWD differs or file missing
// after
string modelPath = Path.Combine(AppContext.BaseDirectory, "models", "model.zip");
if (!File.Exists(modelPath))
throw new FileNotFoundException("ML.NET model file not found.", modelPath);
var loader = new FileModelLoader(_logger, modelPath);
loader.Start(); Defensive patterns
Strategy: validation
Validate before calling
string modelPath = config["MlModel:Path"];
if (string.IsNullOrWhiteSpace(modelPath) || !File.Exists(modelPath))
throw new FileNotFoundException($"Model file not found: {modelPath}"); Type guard
static bool ModelFileExists(string path) => !string.IsNullOrWhiteSpace(path) && File.Exists(path);
Try / catch
try
{
loader.Start();
}
catch (ArgumentException ex) when (ex.Message.Contains("doesn't exist"))
{
logger.LogCritical(ex, "Configured ML.NET model file does not exist.");
throw; // fail fast at startup
} Prevention
- Resolve model paths to absolute paths (Path.Combine(AppContext.BaseDirectory, ...)) instead of CWD-relative ones
- Ensure model files are included in build output/deployment artifacts (Copy to Output Directory)
- Add a startup health check that verifies the model file exists before serving traffic
- Keep model paths in config and verify them in CI against the deployed layout
When it happens
Trigger: Calling predictionEnginePool/model loading pipeline wiring with a FileModelLoader whose path string points to a nonexistent file; a typo'd relative path where the working directory differs from expected; the model file deleted or never produced by training; container image missing the model artifact.
Common situations: ASP.NET Core app registering AddPredictionEnginePool with a model path that exists on the dev machine but not in the container; CI working directory differences; model path configured via appsettings pointing at a staging path; training job failed so the .zip model was never written.
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
- File ' ' does not exist
- Start must be called on a ModelLoader before it can be used.
- column must be of data type
- Duplicate column name
- getter
AI-assisted analysis of dotnet/machinelearning@7b76e69cf9 (2026-09-11).
Data as JSON: /api/errors/3990f77042fb127f.
Report an issue: GitHub.
Appendix: source
Thrown at src/Microsoft.Extensions.ML/ModelLoaders/FileModelLoader.cs:42
private readonly MLContext _context;
private readonly object _lock;
public FileModelLoader(IOptions<MLOptions> contextOptions, ILogger<FileModelLoader> logger)
{
_logger = logger ?? throw new ArgumentNullException(nameof(logger));
_context = contextOptions.Value?.MLContext ?? throw new ArgumentNullException(nameof(contextOptions));
_lock = new object();
}
public void Start(string filePath, bool watchFile)
{
_filePath = filePath;
_reloadToken = new ModelReloadToken();
if (!File.Exists(filePath))
{
throw new ArgumentException($"The provided model file {filePath} doesn't exist.");
}
var directory = Path.GetDirectoryName(filePath);
if (string.IsNullOrEmpty(directory))
{
directory = Directory.GetCurrentDirectory();
}
var file = Path.GetFileName(filePath);
LoadModel();
if (watchFile)
{
_watcher = new FileSystemWatcher(directory, file);
_watcher.EnableRaisingEvents = true;
_watcher.Changed += WatcherChanged;View on GitHub (pinned to 7b76e69cf9)