babalae/better-genshin-impact · error · FileNotFoundException

未找到{featName}中的{assertName}文件

Error message

未找到{featName}中的{assertName}文件

What it means

Thrown by GameTaskManager.LoadAssetImage when the Assets folder exists (either resolution-specific or the 1920x1080 fallback) but the individual asset file named assertName is not found inside it. The path is constructed via Path.Combine(assetsFolder, assertName), so a missing file or an incorrect filename triggers this.

Source

Thrown at BetterGenshinImpact/GameTask/GameTaskManager.cs:170

    /// <returns></returns>
    /// <exception cref="FileNotFoundException"></exception>
    public static Mat LoadAssetImage(string featName, string assertName, ISystemInfo systemInfo, ImreadModes flags = ImreadModes.Color)
    {
        var assetsFolder = Global.Absolute($@"GameTask\{featName}\Assets\{systemInfo.GameScreenSize.Width}x{systemInfo.GameScreenSize.Height}");
        if (!Directory.Exists(assetsFolder))
        {
            assetsFolder = Global.Absolute($@"GameTask\{featName}\Assets\1920x1080");
        }

        if (!Directory.Exists(assetsFolder))
        {
            throw new FileNotFoundException($"未找到{featName}的素材文件夹");
        }

        var filePath = Path.Combine(assetsFolder, assertName);
        if (!File.Exists(filePath))
        {
            throw new FileNotFoundException($"未找到{featName}中的{assertName}文件");
        }

        var mat = Mat.FromStream(File.OpenRead(filePath), flags);
        if (systemInfo.GameScreenSize.Width != 1920)
        {
            mat = ResizeHelper.Resize(mat, systemInfo.AssetScale);
        }

        return mat;
    }

    /// <summary>
    /// 根据捕获区域宽高加载素材图片并缩放
    /// </summary>
    /// <returns></returns>
    /// <exception cref="FileNotFoundException"></exception>
    public static Mat LoadAssetImage(string featName, string assertName, int captureWidth, int captureHeight, ImreadModes flags = ImreadModes.Color)
    {

View on GitHub (pinned to a7cb36712d)

Solutions

  1. Check the exact filename and extension in the resolved Assets folder and compare against assertName.
  2. Log the full constructed filePath to confirm which folder was resolved (resolution-specific vs fallback).
  3. Ensure all referenced asset files are included in the .csproj as Content with CopyToOutputDirectory.
  4. Add a File.Exists guard at the call site with a helpful error message listing available files in the folder.

Example fix

// before
var filePath = Path.Combine(assetsFolder, assertName);
if (!File.Exists(filePath))
    throw new FileNotFoundException($"未找到{featName}中的{assertName}文件");

// after
var filePath = Path.Combine(assetsFolder, assertName);
if (!File.Exists(filePath))
    throw new FileNotFoundException(
        $"未找到{featName}中的{assertName}文件,路径:{filePath}," +
        $"目录内文件:{string.Join(", ", Directory.GetFiles(assetsFolder).Select(Path.GetFileName))}",
        filePath);
Defensive patterns

Strategy: validation

Validate before calling

var filePath = Path.Combine(fallbackFolder, assertName);
if (!File.Exists(filePath))
{
    logger.LogError("素材文件不存在:{Path}", filePath);
    return;
}

Try / catch

try { var mat = GameTaskManager.LoadAssetImage(featName, assertName, systemInfo); }
catch (FileNotFoundException ex) when (ex.Message.Contains(assertName))
{ logger.LogError(ex, "文件缺失:{File}", assertName); }

Prevention

When it happens

Trigger: Calling LoadAssetImage with an assertName that does not exist in the resolved Assets folder. Common causes: filename typo, wrong file extension (e.g. .jpg vs .png), case mismatch, or the asset was never generated/copied.

Common situations: A developer adds a new recognition template reference but forgets to add the corresponding image file; an asset was renamed in code but not on disk; cross-platform case-sensitivity issues when developing on Linux but shipping on Windows.

Related errors


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