{"record":{"id":"9a0340a1fc0a30d9","repo":"dotnet/machinelearning","slug":"filenotfound","errorCode":null,"errorMessage":"FileNotFound","messagePattern":"FileNotFound","errorType":"exception","errorClass":"FileNotFoundException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.Data.Analysis/TextFieldParser.cs","lineNumber":587,"sourceCode":"                throw new ArgumentNullException(nameof(stream));\n            }\n            if (!stream.CanRead)\n            {\n                throw new ArgumentException(Strings.StreamDoesntSupportReading);\n            }\n            if (defaultEncoding == null)\n            {\n                throw new ArgumentNullException(nameof(defaultEncoding));\n            }\n            _reader = new StreamReader(stream, defaultEncoding, detectEncoding);\n            ReadToBuffer();\n        }\n\n        private string ValidatePath(string path)\n        {\n            if (!File.Exists(path))\n            {\n                throw new FileNotFoundException(Strings.FileNotFound);\n            }\n            return path;\n        }\n\n        private bool IgnoreLine(string line)\n        {\n            if (line == null)\n            {\n                return false;\n            }\n            string trimmedLine = line.Trim();\n            if (trimmedLine.Length == 0)\n            {\n                return true;\n            }\n            if (_commentTokens != null)\n            {\n                string[] commentTokens = _commentTokens;","sourceCodeStart":569,"sourceCodeEnd":605,"githubUrl":"https://github.com/dotnet/machinelearning/blob/7b76e69cf964daeca3f1377af6bc5543284d56c6/src/Microsoft.Data.Analysis/TextFieldParser.cs#L569-L605","documentation":"TextFieldParser.ValidatePath throws FileNotFoundException(\"FileNotFound\") when the path passed to the file-based constructor does not exist on disk. Unlike File.Open, this parser checks existence explicitly and reports the generic Strings.FileNotFound message.","triggerScenarios":"Constructing TextFieldParser(string path) with a path that does not exist — typo, wrong working directory, relative path resolved against an unexpected base, or the file deleted between check and use.","commonSituations":"Using a relative path when the process's current directory differs from what the app assumes; case/typo errors in filenames; deployment packaging that omitted a data file; temp files already cleaned up.","solutions":["Check File.Exists(path) before constructing and print the full absolute path on failure","Use Path.GetFullPath to see what the relative path resolves to and correct it","Fix the path or ship/copy the file with your deployment","Prefer passing a FileStream you open yourself for clearer error messages"],"exampleFix":"// before\nvar parser = new TextFieldParser(\"data/input.csv\");\n// after\nstring fullPath = Path.GetFullPath(\"data/input.csv\");\nif (!File.Exists(fullPath))\n    throw new FileNotFoundException($\"Input file missing: {fullPath}\", fullPath);\nvar parser = new TextFieldParser(fullPath);","handlingStrategy":"validation","validationCode":"if (!File.Exists(Path.GetFullPath(path))) throw new FileNotFoundException($\"CSV input not found: {Path.GetFullPath(path)}\", path);","typeGuard":null,"tryCatchPattern":"try { parser = new TextFieldParser(path); } catch (FileNotFoundException ex) { Console.Error.WriteLine($\"Input file missing: {path}\"); throw; }","preventionTips":["Resolve and log absolute paths before opening","Verify deployment includes all data files","Check current working directory assumptions for relative paths"],"tags":["textfieldparser","filenotfoundexception","file-io","path"],"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"}