{"record":{"id":"57f9bc080e6afbda","repo":"babalae/better-genshin-impact","slug":"taskname-assetname","errorCode":null,"errorMessage":"未找到{taskName}中的{assetName}文件","messagePattern":"未找到(.+?)中的(.+?)文件","errorType":"exception","errorClass":"FileNotFoundException","httpStatus":null,"severity":"error","filePath":"BetterGenshinImpact/Core/Recognition/RecognitionAssets.cs","lineNumber":92,"sourceCode":"    }\n\n    private static Mat LoadTemplateImage(string taskName, string assetName, int captureWidth, int captureHeight, ImreadModes flags)\n    {\n        var assetsFolder = Global.Absolute($@\"GameTask\\{taskName}\\Assets\\{captureWidth}x{captureHeight}\");\n        if (!Directory.Exists(assetsFolder))\n        {\n            assetsFolder = Global.Absolute($@\"GameTask\\{taskName}\\Assets\\1920x1080\");\n        }\n\n        if (!Directory.Exists(assetsFolder))\n        {\n            throw new FileNotFoundException($\"未找到{taskName}的素材文件夹\");\n        }\n\n        var filePath = Path.Combine(assetsFolder, assetName);\n        if (!File.Exists(filePath))\n        {\n            throw new FileNotFoundException($\"未找到{taskName}中的{assetName}文件\");\n        }\n\n        using var stream = File.OpenRead(filePath);\n        var mat = Mat.FromStream(stream, flags);\n        if (captureWidth < 1920)\n        {\n            using (mat)\n            {\n                return ResizeHelper.Resize(mat, captureWidth / 1920d);\n            }\n        }\n\n        return mat;\n    }\n\n    private readonly record struct RecognitionAssetCacheKey(string TaskName, string ObjectName, int CaptureWidth, int CaptureHeight);\n}\n","sourceCodeStart":74,"sourceCodeEnd":110,"githubUrl":"https://github.com/babalae/better-genshin-impact/blob/a7cb36712dcb409be610257d877fcea3597e9d6b/BetterGenshinImpact/Core/Recognition/RecognitionAssets.cs#L74-L110","documentation":"LoadTemplateImage found the task's Assets folder but the specific template image (assetName) referenced by Recognition.json is not present. FileNotFoundException identifies exactly which file is missing so the template match for that object cannot run.","triggerScenarios":"A RecognitionObject of type TemplateMatch references a template whose png exists in JSON but is absent on disk under the resolved Assets folder.","commonSituations":"Template png deleted but still referenced; filename typo or casing mismatch between JSON and disk; image added to source control but not committed/deployed; wrong resolution folder searched.","solutions":["Add the missing {assetName} file under GameTask\\{taskName}\\Assets\\1920x1080\\ (and the specific resolution folder if used).","Fix the template filename in Recognition.json so it matches the on-disk name exactly, including case.","Verify the file is included in the project and copied to the output directory.","Clear the RecognitionAssets cache (RecognitionAssets.ClearTask) after correcting the file."],"exampleFix":"// before: Recognition.json references \"btn_start.png\" that is not on disk -> throws\nvar ro = RecognitionAssets.Get(taskName, objectName);\n\n// after: verify the template path the loader will use\nvar file = Path.Combine(Global.Absolute($@\"GameTask\\{taskName}\\Assets\\1920x1080\"), \"btn_start.png\");\nif (!File.Exists(file)) throw new InvalidOperationException($\"Template missing: {file}\");\nvar ro = RecognitionAssets.Get(taskName, objectName);","handlingStrategy":"validation","validationCode":"bool TemplateExists(string taskName, string assetName)\n{\n    var folder = Global.Absolute($@\"GameTask\\{taskName}\\Assets\\1920x1080\");\n    return File.Exists(Path.Combine(folder, assetName));\n}\n\nif (!TemplateExists(taskName, assetName))\n    throw new InvalidOperationException($\"Template {assetName} missing for task {taskName}\");","typeGuard":null,"tryCatchPattern":"try { var ro = RecognitionAssets.Get(taskName, objectName); }\ncatch (FileNotFoundException ex) when (ex.Message.Contains(\"中的\") && ex.Message.Contains(\"文件\"))\n{ Logger.LogError(ex, \"Template file missing.\"); throw; }","preventionTips":["Make template filenames in JSON match the on-disk files exactly, including case.","Commit template images to source control and mark them copy-to-output.","After fixing a file, call RecognitionAssets.ClearTask(taskName) to drop the bad cache entry."],"tags":["assets","game-task","template","asset-missing"],"backgroundTag":null,"analyzedSha":"a7cb36712dcb409be610257d877fcea3597e9d6b","analyzedAt":"2026-08-13T16:44:57.548Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}