babalae/better-genshin-impact · error · InvalidOperationException
当前UI语言为空,无法更新语言文件。
Error message
当前UI语言为空,无法更新语言文件。
What it means
Thrown by OnUpdateUiLanguageAsync when Config.OtherConfig.UiCultureInfoName is null, empty, or whitespace. The culture name is used to build the remote i18n JSON filename, so a blank value cannot map to a downloadable language file. The code treats this as a programmer/state error (InvalidOperationException) rather than prompting the user.
Source
Thrown at BetterGenshinImpact/ViewModel/Pages/CommonSettingsPageViewModel.cs:108
public AllConfig Config { get; set; }
public ObservableCollection<OverlayMetricSettingItem> OverlayMetricItems { get; }
public ObservableCollection<OverlayStyleSettingGroup> OverlayStyleSettingGroups { get; }
public ObservableCollection<string> CountryList { get; } = new();
public ObservableCollection<string> Areas { get; } = new();
public ObservableCollection<string> MapPathingTypes { get; } = ["SIFT", "TemplateMatch"];
[ObservableProperty] private FrozenDictionary<string, string> _languageDict =
new[] { "zh-Hans", "zh-Hant", "en", "ja" }
.ToFrozenDictionary(c => c, c => CultureInfoNameToKVPConverter.GetDisplayName(c));
[RelayCommand]
private async Task OnUpdateUiLanguageAsync()
{
var cultureName = Config.OtherConfig.UiCultureInfoName ?? string.Empty;
if (string.IsNullOrWhiteSpace(cultureName))
{
throw new InvalidOperationException("当前UI语言为空,无法更新语言文件。");
}
if (cultureName == "zh-Hans")
{
await ThemedMessageBox.InformationAsync("zh-Hans 无语言文件,无需更新。");
return;
}
var urls = new[]
{
$"https://raw.githubusercontent.com/babalae/bettergi-i18n/refs/heads/main/i18n/{cultureName}.json",
$"https://cnb.cool/bettergi/bettergi-i18n/-/git/raw/main/i18n/{cultureName}.json"
};
using var httpClient = new HttpClient
{
Timeout = TimeSpan.FromSeconds(30)
};View on GitHub (pinned to a7cb36712d)
Solutions
- Default the language dropdown to zh-Hans in the settings UI so UiCultureInfoName is never blank.
- Validate UiCultureInfoName before invoking the command and show ThemedMessageBox.WarningAsync instead of throwing.
- Ensure Config.OtherConfig initializes UiCultureInfoName to a non-empty fallback (e.g. zh-Hans).
Example fix
// before
var cultureName = Config.OtherConfig.UiCultureInfoName ?? string.Empty;
if (string.IsNullOrWhiteSpace(cultureName))
{
throw new InvalidOperationException("当前UI语言为空,无法更新语言文件。");
}
// after
var cultureName = Config.OtherConfig.UiCultureInfoName ?? string.Empty;
if (string.IsNullOrWhiteSpace(cultureName))
{
await ThemedMessageBox.WarningAsync("请先在设置中选择 UI 语言。");
return;
} Defensive patterns
Strategy: validation
Validate before calling
if (string.IsNullOrWhiteSpace(Config.OtherConfig.UiCultureInfoName))
{
// Do not invoke OnUpdateUiLanguage; prompt the user to pick a language first.
return;
} Prevention
- Default UiCultureInfoName to zh-Hans in the config model so it is never null.
- Disable the 'update language' button in the UI when no language is selected.
- Treat a blank culture as a user-facing warning, not an exceptional state.
When it happens
Trigger: Invoking the 'update language file' command while UiCultureInfoName is unset. Occurs when the config was never initialized, a config migration left it blank, or the settings dropdown was cleared and saved as empty.
Common situations: Fresh install before any language is selected; manually edited config.json with the field removed or blanked; a culture dropdown cleared by the user; config load fell back to a default that leaves the field null.
Related errors
- 未找到名称为 {objectName} 的 RecognitionObject 配置
- 对象 {objectName} 缺少 template 配置
- 表达式 {expression} 未返回 Rect
- 变量 {name} 存在循环引用
- {fieldName} 必须是 1 到 4 个数字
AI-assisted analysis of babalae/better-genshin-impact@a7cb36712d (2026-08-13).
Data as JSON: /api/errors/64006ebc8c120875.
Report an issue: GitHub.