{"record":{"id":"3fc49dab058fcb98","repo":"babalae/better-genshin-impact","slug":"objectname-recognitionobject","errorCode":null,"errorMessage":"未找到名称为 {objectName} 的 RecognitionObject 配置","messagePattern":"未找到名称为 (.+?) 的 RecognitionObject 配置","errorType":"exception","errorClass":"KeyNotFoundException","httpStatus":null,"severity":"error","filePath":"BetterGenshinImpact/Core/Recognition/RecognitionObjectJsonLoader.cs","lineNumber":70,"sourceCode":"                objectName,\n                context.CaptureWidth,\n                context.CaptureHeight,\n                filePath);\n            throw;\n        }\n    }\n\n    public static RecognitionObject Load(RecognitionObjectJsonFile config, string objectName, RecognitionObjectJsonLoadContext context)\n    {\n        ArgumentNullException.ThrowIfNull(config);\n        ArgumentNullException.ThrowIfNull(objectName);\n        ArgumentNullException.ThrowIfNull(context);\n\n        try\n        {\n            if (!config.Objects.TryGetValue(objectName, out var objectConfig))\n            {\n                throw new KeyNotFoundException($\"未找到名称为 {objectName} 的 RecognitionObject 配置\");\n            }\n\n            return new Loader(config, context).BuildRecognitionObject(objectName, objectConfig);\n        }\n        catch (Exception ex)\n        {\n            Logger.LogError(ex,\n                \"Recognition 构建失败: {ObjectName} @ {CaptureWidth}x{CaptureHeight}\",\n                objectName,\n                context.CaptureWidth,\n                context.CaptureHeight);\n            throw;\n        }\n    }\n\n    private sealed class Loader\n    {\n        private static readonly string[] RectFunctionNames =","sourceCodeStart":52,"sourceCodeEnd":88,"githubUrl":"https://github.com/babalae/better-genshin-impact/blob/a7cb36712dcb409be610257d877fcea3597e9d6b/BetterGenshinImpact/Core/Recognition/RecognitionObjectJsonLoader.cs#L52-L88","documentation":"After the JSON loads, RecognitionObjectJsonLoader.Load looks up the requested objectName in the config.Objects map. If that key is absent it throws KeyNotFoundException, because there is no recognition definition to build. The catch wrapper logs the failure and rethrows.","triggerScenarios":"Calling Load / RecognitionAssets.Get with an objectName that is not present as a key in the objects map of the task's Recognition.json.","commonSituations":"Object renamed in JSON but not in calling code (or vice versa); typo in the objectName string; object defined in a different task; copy-paste of a task name without updating object keys.","solutions":["Add the missing objectName entry to the objects map in Recognition.json.","Correct the objectName string in code so it matches an existing key exactly, including case.","Search the JSON for similar keys to catch typos or renamed identifiers.","Keep object names in a shared constants class to avoid string drift."],"exampleFix":"// before\nvar ro = RecognitionAssets.Get(\"AutoFishing\", \"RodButton\"); // key not in objects map\n\n// after\n// confirm the key exists in the loaded config first\nvar config = JsonConvert.DeserializeObject<RecognitionObjectJsonFile>(File.ReadAllText(jsonPath));\nif (!config!.Objects.ContainsKey(\"RodButton\"))\n    throw new InvalidOperationException(\"Object 'RodButton' missing from Recognition.json\");\nvar ro = RecognitionAssets.Get(\"AutoFishing\", \"RodButton\");","handlingStrategy":"validation","validationCode":"var json = File.ReadAllText(filePath, Encoding.UTF8);\nvar config = JsonConvert.DeserializeObject<RecognitionObjectJsonFile>(json)\n    ?? throw new InvalidOperationException(\"Recognition.json is null\");\nif (!config.Objects.ContainsKey(objectName))\n    throw new InvalidOperationException($\"Object '{objectName}' not declared in {filePath}\");\nreturn RecognitionObjectJsonLoader.LoadFromFile(filePath, objectName, context);","typeGuard":null,"tryCatchPattern":"try { return RecognitionObjectJsonLoader.LoadFromFile(filePath, objectName, context); }\ncatch (KeyNotFoundException ex) when (ex.Message.Contains(\"的 RecognitionObject 配置\"))\n{ Logger.LogError(ex, \"Object '{Name}' not in {Path}\", objectName, filePath); throw; }","preventionTips":["Centralize object name strings in a constants class shared by code and JSON tooling.","Add a test that asserts every objectName requested in code exists in its task's Recognition.json.","Run a linter that flags objectName references not present in the objects map."],"tags":["config","recognition","key-not-found","validation"],"backgroundTag":null,"analyzedSha":"a7cb36712dcb409be610257d877fcea3597e9d6b","analyzedAt":"2026-08-13T16:44:57.548Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}