{"record":{"id":"4cb55b58af62a06d","repo":"babalae/better-genshin-impact","slug":"error-4cb55b","errorCode":null,"errorMessage":"自动钓鱼模型文件不存在","messagePattern":"自动钓鱼模型文件不存在","errorType":"exception","errorClass":"FileNotFoundException","httpStatus":null,"severity":"error","filePath":"BetterGenshinImpact/Core/Recognition/ONNX/YOLO/Predictor.cs","lineNumber":19,"sourceCode":"﻿using BetterGenshinImpact.Core.Config;\nusing Microsoft.ML.OnnxRuntime;\nusing System;\nusing System.IO;\nusing System.Text.Json;\n\nnamespace BetterGenshinImpact.Core.Recognition.ONNX.YOLO;\n\n[Obsolete]\npublic class Predictor\n{\n    private readonly InferenceSession _session;\n    private readonly string[] labels;\n\n    public Predictor()\n    {\n        var options = new SessionOptions();\n        var modelPath = Global.Absolute(@\"Assets\\Model\\Fish\\bgi_fish.onnx\");\n        if (!File.Exists(modelPath)) throw new FileNotFoundException(\"自动钓鱼模型文件不存在\", modelPath);\n\n        _session = new InferenceSession(modelPath, options);\n\n        var wordJsonPath = Global.Absolute(@\"Assets\\Model\\Fish\\label.json\");\n        if (!File.Exists(wordJsonPath)) throw new FileNotFoundException(\"自动钓鱼模型分类文件不存在\", wordJsonPath);\n\n        var json = File.ReadAllText(wordJsonPath);\n        labels = JsonSerializer.Deserialize<string[]>(json) ?? throw new Exception(\"label.json deserialize failed\");\n    }\n}\n","sourceCodeStart":1,"sourceCodeEnd":30,"githubUrl":"https://github.com/babalae/better-genshin-impact/blob/a7cb36712dcb409be610257d877fcea3597e9d6b/BetterGenshinImpact/Core/Recognition/ONNX/YOLO/Predictor.cs#L1-L30","documentation":"Predictor (marked [Obsolete]) is the legacy auto-fishing YOLO model loader. It resolves Assets\\Model\\Fish\\bgi_fish.onnx and throws FileNotFoundException when the model is missing, blocking Predictor construction. Newer fishing code uses BgiOnnxFactory/BgiYoloPredictor instead.","triggerScenarios":"Calling new Predictor() when bgi_fish.onnx is absent, typically because the legacy code path was invoked after the asset was removed or never restored.","commonSituations":"Asset dropped during a refactor; build excludes the Fish folder; old reference path used; running on a clean checkout that omits large binary assets.","solutions":["Prefer the replacement fishing recognizer (BgiYoloPredictor via BgiOnnxFactory and BgiOnnxModel.BgiFish) instead of the obsolete Predictor.","If the legacy path must run, restore bgi_fish.onnx under Assets\\Model\\Fish\\.","Remove dead usages of the obsolete Predictor so the throw cannot be reached.","Guard construction with File.Exists and report the missing asset."],"exampleFix":"// before (obsolete, throws when onnx missing)\nvar predictor = new Predictor();\n\n// after: use the registered model via the factory\nvar predictor = App.ServiceProvider.GetRequiredService<BgiOnnxFactory>()\n    .CreateYoloPredictor(BgiOnnxModel.BgiFish);","handlingStrategy":"fallback","validationCode":"var modelPath = Global.Absolute(@\"Assets\\Model\\Fish\\bgi_fish.onnx\");\nif (!File.Exists(modelPath))\n    throw new InvalidOperationException($\"Fish model missing: {modelPath}\");\n#pragma warning disable CS0612\nvar predictor = new Predictor();\n#pragma warning restore CS0612","typeGuard":null,"tryCatchPattern":"try { var p = new Predictor(); }\ncatch (FileNotFoundException ex) when (ex.Message.Contains(\"自动钓鱼模型文件不存在\"))\n{ Logger.LogError(ex, \"Legacy fish model missing; migrate to BgiOnnxFactory/BgiYoloPredictor.\"); throw; }","preventionTips":["Migrate off the [Obsolete] Predictor to BgiYoloPredictor via BgiOnnxFactory and BgiOnnxModel.BgiFish.","If you must keep the legacy path, validate the onnx file exists first.","Remove dead references to Predictor so the throw cannot be reached."],"tags":["yolo","onnx","fishing","asset-missing","obsolete"],"backgroundTag":null,"analyzedSha":"a7cb36712dcb409be610257d877fcea3597e9d6b","analyzedAt":"2026-08-13T16:44:57.548Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}