babalae/better-genshin-impact · error · FileNotFoundException

自动钓鱼模型文件不存在

Error message

自动钓鱼模型文件不存在

What it means

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.

Solutions

  1. Prefer the replacement fishing recognizer (BgiYoloPredictor via BgiOnnxFactory and BgiOnnxModel.BgiFish) instead of the obsolete Predictor.
  2. If the legacy path must run, restore bgi_fish.onnx under Assets\Model\Fish\.
  3. Remove dead usages of the obsolete Predictor so the throw cannot be reached.
  4. Guard construction with File.Exists and report the missing asset.

Example fix

// before (obsolete, throws when onnx missing)
var predictor = new Predictor();

// after: use the registered model via the factory
var predictor = App.ServiceProvider.GetRequiredService<BgiOnnxFactory>()
    .CreateYoloPredictor(BgiOnnxModel.BgiFish);
Defensive patterns

Strategy: fallback

Validate before calling

var modelPath = Global.Absolute(@"Assets\Model\Fish\bgi_fish.onnx");
if (!File.Exists(modelPath))
    throw new InvalidOperationException($"Fish model missing: {modelPath}");
#pragma warning disable CS0612
var predictor = new Predictor();
#pragma warning restore CS0612

Try / catch

try { var p = new Predictor(); }
catch (FileNotFoundException ex) when (ex.Message.Contains("自动钓鱼模型文件不存在"))
{ Logger.LogError(ex, "Legacy fish model missing; migrate to BgiOnnxFactory/BgiYoloPredictor."); throw; }

Prevention

When it happens

Trigger: 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.

Common situations: Asset dropped during a refactor; build excludes the Fish folder; old reference path used; running on a clean checkout that omits large binary assets.

Related errors


AI-assisted analysis of babalae/better-genshin-impact@a7cb36712d (2026-08-13). Data as JSON: /api/errors/4cb55b58af62a06d. Report an issue: GitHub.

Appendix: source

Thrown at BetterGenshinImpact/Core/Recognition/ONNX/YOLO/Predictor.cs:19

using BetterGenshinImpact.Core.Config;
using Microsoft.ML.OnnxRuntime;
using System;
using System.IO;
using System.Text.Json;

namespace BetterGenshinImpact.Core.Recognition.ONNX.YOLO;

[Obsolete]
public class Predictor
{
    private readonly InferenceSession _session;
    private readonly string[] labels;

    public Predictor()
    {
        var options = new SessionOptions();
        var modelPath = Global.Absolute(@"Assets\Model\Fish\bgi_fish.onnx");
        if (!File.Exists(modelPath)) throw new FileNotFoundException("自动钓鱼模型文件不存在", modelPath);

        _session = new InferenceSession(modelPath, options);

        var wordJsonPath = Global.Absolute(@"Assets\Model\Fish\label.json");
        if (!File.Exists(wordJsonPath)) throw new FileNotFoundException("自动钓鱼模型分类文件不存在", wordJsonPath);

        var json = File.ReadAllText(wordJsonPath);
        labels = JsonSerializer.Deserialize<string[]>(json) ?? throw new Exception("label.json deserialize failed");
    }
}

View on GitHub (pinned to a7cb36712d)