babalae/better-genshin-impact · critical · FileNotFoundException

config.json 未找到

Error message

config.json 未找到

What it means

Thrown as a FileNotFoundException by LoadConfigData when the file GameTask/AutoLeyLineOutcrop/Assets/config.json does not exist on disk. This file contains the static ley line position data, map positions, and error thresholds that the strategy-matching and navigation logic depend on. It is a bundled asset that should ship with the application; its absence indicates a corrupted or incomplete installation.

Source

Thrown at BetterGenshinImpact/GameTask/AutoLeyLineOutcrop/AutoLeyLineOutcropTask.cs:226

        if (_taskParam.FightConfig.Timeout <= 0)
        {
            _taskParam.FightConfig.Timeout = _taskParam.Timeout > 0 ? _taskParam.Timeout : 120;
        }
        else
        {
            _taskParam.Timeout = _taskParam.FightConfig.Timeout;
        }
    }

    private void LoadConfigData()
    {
        // Load and validate the static ley line route config from disk.
        var workDir = Global.Absolute(@"GameTask\AutoLeyLineOutcrop");
        var configPath = Path.Combine(workDir, "Assets", "config.json");
        if (!File.Exists(configPath))
        {
            throw new FileNotFoundException("config.json 未找到", configPath);
        }

        var json = File.ReadAllText(configPath);
        _configData = JsonSerializer.Deserialize<AutoLeyLineConfigData>(json)
                      ?? throw new Exception("config.json 解析失败");
    }

    private void LoadRecognitionObjects()
    {
        // Template ROIs are tuned for the 1080p capture region.
        _openRo = BuildTemplate("Assets/icon/open.png");
        _closeRo = BuildTemplate("Assets/icon/close.png");
        _paimonMenuRo = BuildTemplate("Assets/icon/paimon_menu.png", new Rect(0, 0, ScaleTo1080(640), ScaleTo1080(216)));
        _boxIconRo = BuildTemplate("Assets/icon/box.png");
        _mapSettingButtonRo = BuildTemplate("Assets/icon/map_setting_button.bmp");
        _handbookTrackActionRo = BuildTemplate("Assets/icon/handbook_track_action_left.png", HandbookTrackActionButtonRoi, 0.72);

        _ocrRo1 = RecognitionObject.Ocr(ScaleTo1080(800), ScaleTo1080(200), ScaleTo1080(300), ScaleTo1080(100));

View on GitHub (pinned to a7cb36712d)

Solutions

  1. Reinstall or re-download the application to restore the bundled Assets/config.json file.
  2. If building from source, verify the file is marked as CopyToOutputDirectory in the .csproj and exists in the build output.
  3. Check if antivirus software quarantined the file and restore/exclude it.
  4. Manually verify the file exists at Global.Absolute(@"GameTask\AutoLeyLineOutcrop\Assets\config.json").
Defensive patterns

Strategy: validation

Validate before calling

// Before starting the task, verify config.json exists
var configPath = Path.Combine(Global.Absolute(@"GameTask\AutoLeyLineOutcrop"), "Assets", "config.json");
if (!File.Exists(configPath))
{
    Logger.LogError("config.json 不存在,请重新安装程序: {Path}", configPath);
    return;
}

Try / catch

catch (FileNotFoundException ex) when (ex.Message.Contains("config.json 未找到"))
{
    logger.LogError("地脉花配置文件缺失,请重新安装程序: {Path}", ex.FileName);
    ThemedMessageBox.Error("配置文件缺失,请重新安装程序", "文件未找到");
}

Prevention

When it happens

Trigger: LoadConfigData (called from Initialize at task start) resolves the path via Global.Absolute and checks File.Exists. Fires when the deployment is missing the Assets/config.json file under the AutoLeyLineOutcrop task directory.

Common situations: The application was installed from a partial or interrupted download; an antivirus quarantined the JSON file; a user manually deleted or moved assets; a build/packaging step excluded the JSON from the output directory; running from source without copying assets to the build output.

Related errors


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