{"record":{"id":"71aa2144c8003cd4","repo":"babalae/better-genshin-impact","slug":"materialname-materialtype-i","errorCode":null,"errorMessage":"未找到材料 {_materialName} 的材料类型，请传入 materialType 或检查 item.csv。","messagePattern":"未找到材料 (.+?) 的材料类型，请传入 materialType 或检查 item\\.csv。","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"BetterGenshinImpact/GameTask/Common/Job/CraftMaterialTask.cs","lineNumber":188,"sourceCode":"\n    /// <summary>\n    /// 解析材料筛选类型，优先使用调用方显式传入的类型。\n    /// </summary>\n    /// <returns>材料筛选类型。</returns>\n    /// <exception cref=\"InvalidOperationException\">未传入材料类型且 CSV 中没有对应材料类型时抛出。</exception>\n    private string ResolveMaterialType()\n    {\n        if (!string.IsNullOrWhiteSpace(_materialType))\n        {\n            return _materialType;\n        }\n\n        if (MaterialTypes.Value.TryGetValue(_materialName, out var materialType) && !string.IsNullOrWhiteSpace(materialType))\n        {\n            return materialType;\n        }\n\n        throw new InvalidOperationException($\"未找到材料 {_materialName} 的材料类型，请传入 materialType 或检查 item.csv。\");\n    }\n\n    /// <summary>\n    /// 从物品原型 CSV 读取材料类型映射。\n    /// </summary>\n    /// <returns>材料名到材料类型的映射。</returns>\n    private static Dictionary<string, string> LoadMaterialTypes()\n    {\n        var path = Global.Absolute(@\"Assets\\Model\\ItemV2\\item.csv\");\n        var result = new Dictionary<string, string>();\n\n        using var parser = new TextFieldParser(path, Encoding.UTF8)\n        {\n            TextFieldType = FieldType.Delimited,\n            HasFieldsEnclosedInQuotes = true,\n            TrimWhiteSpace = false\n        };\n        parser.SetDelimiters(\",\");","sourceCodeStart":170,"sourceCodeEnd":206,"githubUrl":"https://github.com/babalae/better-genshin-impact/blob/a7cb36712dcb409be610257d877fcea3597e9d6b/BetterGenshinImpact/GameTask/Common/Job/CraftMaterialTask.cs#L170-L206","documentation":"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.","triggerScenarios":"Constructing new CraftMaterialTask(\"新材料名\", 5) without a materialType argument, where '新材料名' does not exist in the material_type column of Assets/Model/ItemV2/item.csv.","commonSituations":"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.","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."],"exampleFix":"// before\nvar task = new CraftMaterialTask(\"新素材\", 10);\nawait task.Start(ct); // throws — no material type found\n\n// after\nvar task = new CraftMaterialTask(\"新素材\", 10, \"天赋培养材料\");\nawait task.Start(ct);","handlingStrategy":"validation","validationCode":"// Check item.csv for the material before running the task\nif (!MaterialTypes.Value.ContainsKey(materialName))\n{\n    // pass explicit materialType or abort\n}","typeGuard":"null","tryCatchPattern":"try { await task.Start(ct); }\ncatch (InvalidOperationException ex) when (ex.Message.Contains(\"材料类型\")) { /* pass materialType explicitly, retry */ }","preventionTips":["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."],"tags":["crafting","csv-data","material-type","config"],"backgroundTag":null,"analyzedSha":"a7cb36712dcb409be610257d877fcea3597e9d6b","analyzedAt":"2026-08-13T16:44:57.548Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}