{"record":{"id":"df9becd3ee66d817","repo":"dotnet/machinelearning","slug":"empty-file","errorCode":null,"errorMessage":"Empty file","messagePattern":"Empty file","errorType":"exception","errorClass":"System.FormatException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.Data.Analysis/DataFrame.IO.cs","lineNumber":438,"sourceCode":"                                }\n                            }\n                            else\n                            {\n                                linesForGuessType.Add((rowline, fields));\n                                numberOfColumns = Math.Max(numberOfColumns, fields.Length);\n                            }\n                        }\n                    }\n                    ++rowline;\n                    if (rowline == guessRows || guessRows == 0)\n                    {\n                        break;\n                    }\n                }\n\n                if (rowline == 0)\n                {\n                    throw new FormatException(Strings.EmptyFile);\n                }\n\n                columns = new List<DataFrameColumn>(numberOfColumns);\n                // Guesses types or looks up dataTypes and adds columns.\n                for (int i = 0; i < numberOfColumns; ++i)\n                {\n                    Type kind = dataTypes == null ? GuessKind(i, linesForGuessType, guessTypeFunction) : dataTypes[i];\n                    columns.Add(CreateColumn(kind, columnNames, i));\n                }\n            }\n\n            DataFrame ret = new DataFrame(columns);\n\n            // Fill values.\n            using (var textReader = wrappedReader.GetTextReader())\n            {\n                TextFieldParser parser = new TextFieldParser(textReader);\n                parser.SetDelimiters(separator.ToString());","sourceCodeStart":420,"sourceCodeEnd":456,"githubUrl":"https://github.com/dotnet/machinelearning/blob/7b76e69cf964daeca3f1377af6bc5543284d56c6/src/Microsoft.Data.Analysis/DataFrame.IO.cs#L420-L456","documentation":"ReadCsvLinesIntoDataFrame counts the header/data rows it reads; if rowline == 0 nothing was read, meaning the input contains no lines, and it throws FormatException(Strings.EmptyFile). The library requires at least one line (header or data) to build columns.","triggerScenarios":"Loading a zero-byte file or empty string via LoadCsv/LoadCsvFromString; a stream positioned at EOF; input containing only whitespace/BOM such that no rows are parsed.","commonSituations":"CSV export job produced an empty file; network transfer truncated the file; reading a file before it was written; opening the wrong path (an empty placeholder).","solutions":["Check the file/input length before calling LoadCsv and handle empty inputs separately","Fix the upstream producer so the CSV file is fully written before reading","If empty files are legitimate, catch FormatException and return an empty DataFrame","Verify the stream position (seek to 0) before passing it to LoadCsv"],"exampleFix":"// before\nvar df = DataFrame.LoadCsv(path);\n// after\nvar lines = File.ReadAllLines(path);\nif (lines.Length == 0) return new DataFrame();\nvar df = DataFrame.LoadCsv(new MemoryStream(Encoding.UTF8.GetBytes(string.Join(\"\\n\", lines))));","handlingStrategy":"try-catch","validationCode":"var info = new FileInfo(path);\nif (info.Length == 0) return new DataFrame(); // skip load\n","typeGuard":null,"tryCatchPattern":"try { return DataFrame.LoadCsv(stream); } catch (FormatException ex) when (ex.Message == \"Empty file\") { return new DataFrame(); }","preventionTips":["Check file size before loading","Wait for producer completion (file-ready signals) before reading","Seek streams back to 0 before parsing"],"tags":["csv","empty-input","format"],"backgroundTag":"empty-required-field","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"}