{"record":{"id":"3990f77042fb127f","repo":"dotnet/machinelearning","slug":"the-provided-model-file-filepath-doesn-t-exist","errorCode":null,"errorMessage":"The provided model file {filePath} doesn't exist.","messagePattern":"The provided model file (.+?) doesn't exist\\.","errorType":"validation","errorClass":"ArgumentException","httpStatus":null,"severity":"critical","filePath":"src/Microsoft.Extensions.ML/ModelLoaders/FileModelLoader.cs","lineNumber":42,"sourceCode":"        private readonly MLContext _context;\n\n        private readonly object _lock;\n\n        public FileModelLoader(IOptions<MLOptions> contextOptions, ILogger<FileModelLoader> logger)\n        {\n            _logger = logger ?? throw new ArgumentNullException(nameof(logger));\n            _context = contextOptions.Value?.MLContext ?? throw new ArgumentNullException(nameof(contextOptions));\n            _lock = new object();\n        }\n\n        public void Start(string filePath, bool watchFile)\n        {\n            _filePath = filePath;\n            _reloadToken = new ModelReloadToken();\n\n            if (!File.Exists(filePath))\n            {\n                throw new ArgumentException($\"The provided model file {filePath} doesn't exist.\");\n            }\n\n            var directory = Path.GetDirectoryName(filePath);\n\n            if (string.IsNullOrEmpty(directory))\n            {\n                directory = Directory.GetCurrentDirectory();\n            }\n\n            var file = Path.GetFileName(filePath);\n\n            LoadModel();\n\n            if (watchFile)\n            {\n                _watcher = new FileSystemWatcher(directory, file);\n                _watcher.EnableRaisingEvents = true;\n                _watcher.Changed += WatcherChanged;","sourceCodeStart":24,"sourceCodeEnd":60,"githubUrl":"https://github.com/dotnet/machinelearning/blob/7b76e69cf964daeca3f1377af6bc5543284d56c6/src/Microsoft.Extensions.ML/ModelLoaders/FileModelLoader.cs#L24-L60","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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."],"exampleFix":"// before\nvar loader = new FileModelLoader(_logger, \"models/model.zip\");\nloader.Start(); // ArgumentException if CWD differs or file missing\n// after\nstring modelPath = Path.Combine(AppContext.BaseDirectory, \"models\", \"model.zip\");\nif (!File.Exists(modelPath))\n    throw new FileNotFoundException(\"ML.NET model file not found.\", modelPath);\nvar loader = new FileModelLoader(_logger, modelPath);\nloader.Start();","handlingStrategy":"validation","validationCode":"string modelPath = config[\"MlModel:Path\"];\nif (string.IsNullOrWhiteSpace(modelPath) || !File.Exists(modelPath))\n    throw new FileNotFoundException($\"Model file not found: {modelPath}\");","typeGuard":"static bool ModelFileExists(string path) => !string.IsNullOrWhiteSpace(path) && File.Exists(path);","tryCatchPattern":"try\n{\n    loader.Start();\n}\ncatch (ArgumentException ex) when (ex.Message.Contains(\"doesn't exist\"))\n{\n    logger.LogCritical(ex, \"Configured ML.NET model file does not exist.\");\n    throw; // fail fast at startup\n}","preventionTips":["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"],"tags":["mlnet","file-not-found","model-loading","path-configuration","dotnet"],"backgroundTag":"file-not-found","analyzedSha":"7b76e69cf964daeca3f1377af6bc5543284d56c6","analyzedAt":"2026-09-11T12:35:38.930Z","contentChangedAt":"2026-09-11T12:35:38.930Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}