babalae/better-genshin-impact · error · InvalidDataException
物品原型表缺少表头。
Error message
物品原型表缺少表头。
What it means
Thrown as InvalidDataException by LoadWeaponNames when parser.ReadFields() returns null on the very first read (the header row). TextFieldParser.ReadFields returns null only when there is no data to read, meaning item.csv exists but is completely empty (zero bytes or only whitespace).
Source
Thrown at BetterGenshinImpact/GameTask/CharacterDevelopment/WeaponNameMatcher.cs:182
}
private static IReadOnlyList<string> LoadWeaponNames()
{
var path = Global.Absolute(WeaponPrototypePath);
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;
}View on GitHub (pinned to a7cb36712d)
Solutions
- Check the file size of item.csv — if it is near-zero bytes, restore it from the repository.
- Verify git-lfs or sparse-checkout pulled the file content, not just a pointer.
- Rebuild from clean to ensure the asset is properly embedded/copied.
Example fix
null
Defensive patterns
Strategy: validation
Validate before calling
var info = new FileInfo(path);
if (!info.Exists || info.Length == 0) { /* file empty or missing — restore */ } Type guard
null
Try / catch
try { var headers = parser.ReadFields(); }
catch (InvalidDataException) { /* empty CSV — restore asset */ } Prevention
- Check file size of item.csv after build/deploy as part of CI.
- Use git-lfs smudge check to ensure content was fetched.
When it happens
Trigger: item.csv exists at the correct path but has zero content or only whitespace/newlines, so ReadFields() cannot produce a header array.
Common situations: The asset file was created as an empty placeholder during an interrupted download or build. A git checkout left the file empty due to LFS or sparse-checkout misconfiguration. The file was truncated to zero bytes by a crash during write.
Related errors
- 武器名称表中没有可用的武器。
- 物品原型表存在列数不足的记录。
- 物品原型表中没有 item_class_id 以 weapon: 开头的武器记录。
- 未找到物品 ONNX 配套表格。
- 物品原型表存在无法读取的记录。
AI-assisted analysis of babalae/better-genshin-impact@a7cb36712d (2026-08-13).
Data as JSON: /api/errors/ac33b24429a06d3b.
Report an issue: GitHub.