huiyadanli/RevokeMsgPatcher · error · InvalidOperationException

No valid version directories found in: {searchDirectory}

Error message

No valid version directories found in: {searchDirectory}

What it means

TargetInfo.GetAbsolutePath resolves a '{version}' placeholder by scanning subdirectories of a search directory and keeping those whose name has >= 2 dots and parses as a Version. If none qualify, it throws InvalidOperationException listing the search directory.

Source

Thrown at RevokeMsgPatcher/Model/TargetInfo.cs:76

                foreach (var directory in directories)
                {
                    var dirName = Path.GetFileName(directory);

                    // 检查是否包含至少两个点
                    if (dirName.Count(c => c == '.') >= 2)
                    {
                        // 尝试解析为版本号
                        if (Version.TryParse(dirName.Replace("-","."), out Version version))
                        {
                            validVersions.Add(new Tuple<string, Version>(dirName, version));
                        }
                    }
                }

                if (validVersions.Count == 0)
                {
                    throw new InvalidOperationException($"No valid version directories found in: {searchDirectory}");
                }

                // 找到版本号最大的目录
                var maxVersionDir = validVersions.OrderByDescending(v => v.Item2).First().Item1;

                // 构建完整路径
                var fullRelativePath = RelativePath.Replace("{version}", maxVersionDir);
                return Path.Combine(installPath, fullRelativePath);
            }
            else
            {
                return Path.Combine(installPath, RelativePath);
            }
        }
    }
}

View on GitHub (pinned to 89cbbb3f0c)

Solutions

  1. Point at the real install path that contains the versions subfolder.
  2. Confirm the version directory name has >= 2 dots and parses (e.g. 9.9.9, or 3.2.1-5 after the '-'->'.' normalization).
  3. If the app uses a non-standard version dir scheme, the TargetInfo config or the >=2-dot rule needs updating.
Defensive patterns

Strategy: validation

Validate before calling

string searchDirectory = Path.Combine(installPath, prefixPath);
if (!Directory.Exists(searchDirectory))
{
    return ""; // matches GetAbsolutePath's own empty-return for a missing dir
}
bool hasVersionDir = Directory.GetDirectories(searchDirectory)
    .Any(d => Path.GetFileName(d).Count(c => c == '.') >= 2);
if (!hasVersionDir)
{
    MessageBox.Show($"{searchDirectory} 下未找到有效的版本目录。");
}

Prevention

When it happens

Trigger: A TargetInfo.RelativePath containing '{version}' but the corresponding directory has no version-named subdirs (e.g. the app's versions folder is empty, or names have fewer than 2 dots or are non-parseable like a single-segment number).

Common situations: Wrong install path; app stores versions in a sibling directory that does not match the >=2-dot rule; a fresh install whose versions subfolder has not been populated yet.

Related errors


AI-assisted analysis of huiyadanli/RevokeMsgPatcher@89cbbb3f0c (2026-08-13). Data as JSON: /api/errors/ad2e0d37088d4b39. Report an issue: GitHub.