babalae/better-genshin-impact · error · InvalidDataException
物品原型表存在无法读取的记录。
Error message
物品原型表存在无法读取的记录。
What it means
Thrown as InvalidDataException by LoadWeaponNames inside the row-reading loop when parser.ReadFields() returns null for a data row (after headers were already read successfully). This indicates the CSV has malformed content mid-file that TextFieldParser cannot parse into fields — typically a quoting or delimiter inconsistency on a specific line.
Source
Thrown at BetterGenshinImpact/GameTask/CharacterDevelopment/WeaponNameMatcher.cs:187
if (!File.Exists(path))
{
throw new FileNotFoundException("未找到物品 ONNX 配套表格。", path);
}
using var parser = new TextFieldParser(path, Encoding.UTF8)
{
TextFieldType = FieldType.Delimited,
HasFieldsEnclosedInQuotes = true,
TrimWhiteSpace = false
};
parser.SetDelimiters(",");
var headers = parser.ReadFields()
?? throw new InvalidDataException("物品原型表缺少表头。");
var rows = new List<string[]>();
while (!parser.EndOfData)
{
rows.Add(parser.ReadFields()
?? throw new InvalidDataException("物品原型表存在无法读取的记录。"));
}
return ExtractWeaponNames(headers, rows);
}
private static int FindRequiredColumn(IReadOnlyList<string> headers, string columnName)
{
for (var i = 0; i < headers.Count; i++)
{
if (string.Equals(headers[i].Trim(), columnName, StringComparison.OrdinalIgnoreCase))
{
return i;
}
}
throw new InvalidDataException($"物品原型表缺少必需列 {columnName}。");
}
}View on GitHub (pinned to a7cb36712d)
Solutions
- Inspect item.csv line-by-line around the suspected position for quoting or comma issues.
- Restore item.csv from a clean repository copy.
- If the CSV is generated, fix the export logic to properly quote fields containing commas.
Example fix
null
Defensive patterns
Strategy: try-catch
Validate before calling
null
Type guard
null
Try / catch
while (!parser.EndOfData)
{
try { var fields = parser.ReadFields() ?? throw new InvalidDataException(); rows.Add(fields); }
catch (Exception ex) { /* log line number, skip or abort depending on tolerance */ }
} Prevention
- Use a CSV validator on item.csv after any modification.
- Ensure consistent quoting and encoding (UTF-8) when regenerating the file.
When it happens
Trigger: A data row in item.csv has unmatched quotes, an invalid escape sequence, or a delimiter configuration that makes TextFieldParser fail to produce fields for that line.
Common situations: Hand-editing item.csv introduced a syntax error in one row. A data export tool produced a row with embedded commas inside unquoted fields. The file has mixed encodings causing byte-level corruption on certain rows.
Related errors
AI-assisted analysis of babalae/better-genshin-impact@a7cb36712d (2026-08-13).
Data as JSON: /api/errors/f37bd68fe8827409.
Report an issue: GitHub.