babalae/better-genshin-impact · error · InvalidOperationException
未找到材料 {_materialName} 的材料类型,请传入 materialType 或检查 item.csv。
Error message
未找到材料 {_materialName} 的材料类型,请传入 materialType 或检查 item.csv。 What it means
Thrown as InvalidOperationException by CraftMaterialTask.ResolveMaterialType when no explicit materialType was passed to the constructor AND the lazily-loaded MaterialTypes dictionary (from item.csv) does not contain an entry for _materialName, or its value is blank. The crafting UI requires a material filter category to narrow the list; without it the task cannot proceed.
Source
Thrown at BetterGenshinImpact/GameTask/Common/Job/CraftMaterialTask.cs:188
/// <summary>
/// 解析材料筛选类型,优先使用调用方显式传入的类型。
/// </summary>
/// <returns>材料筛选类型。</returns>
/// <exception cref="InvalidOperationException">未传入材料类型且 CSV 中没有对应材料类型时抛出。</exception>
private string ResolveMaterialType()
{
if (!string.IsNullOrWhiteSpace(_materialType))
{
return _materialType;
}
if (MaterialTypes.Value.TryGetValue(_materialName, out var materialType) && !string.IsNullOrWhiteSpace(materialType))
{
return materialType;
}
throw new InvalidOperationException($"未找到材料 {_materialName} 的材料类型,请传入 materialType 或检查 item.csv。");
}
/// <summary>
/// 从物品原型 CSV 读取材料类型映射。
/// </summary>
/// <returns>材料名到材料类型的映射。</returns>
private static Dictionary<string, string> LoadMaterialTypes()
{
var path = Global.Absolute(@"Assets\Model\ItemV2\item.csv");
var result = new Dictionary<string, string>();
using var parser = new TextFieldParser(path, Encoding.UTF8)
{
TextFieldType = FieldType.Delimited,
HasFieldsEnclosedInQuotes = true,
TrimWhiteSpace = false
};
parser.SetDelimiters(",");View on GitHub (pinned to a7cb36712d)
Solutions
- Pass the materialType explicitly to the constructor: new CraftMaterialTask(name, qty, "武器突破材料").
- Verify the material name exactly matches an item_name in item.csv and that its material_type is non-empty.
- Update item.csv if the material is new and not yet listed.
Example fix
// before
var task = new CraftMaterialTask("新素材", 10);
await task.Start(ct); // throws — no material type found
// after
var task = new CraftMaterialTask("新素材", 10, "天赋培养材料");
await task.Start(ct); Defensive patterns
Strategy: validation
Validate before calling
// Check item.csv for the material before running the task
if (!MaterialTypes.Value.ContainsKey(materialName))
{
// pass explicit materialType or abort
} Type guard
null
Try / catch
try { await task.Start(ct); }
catch (InvalidOperationException ex) when (ex.Message.Contains("材料类型")) { /* pass materialType explicitly, retry */ } Prevention
- Always pass an explicit materialType when the material may not be in item.csv.
- Keep item.csv updated with new materials after each game version update.
When it happens
Trigger: Constructing new CraftMaterialTask("新材料名", 5) without a materialType argument, where '新材料名' does not exist in the material_type column of Assets/Model/ItemV2/item.csv.
Common situations: The material name was typed incorrectly or uses a different localization than what is in item.csv. A new material was added in a game update but item.csv was not updated. The material is a consumable/food that has no material_type classification.
Related errors
- 未指定按键,无法转换为VK。
- 不支持的 OCR 引擎类型
- 不支持的 Paddle OCR 模型配置
- 无效的推理设备
- PaddleOCR config file {modelConfigFileName} not found: {conf
AI-assisted analysis of babalae/better-genshin-impact@a7cb36712d (2026-08-13).
Data as JSON: /api/errors/71aa2144c8003cd4.
Report an issue: GitHub.