ZyperWave/ZyperWinOptimize · error · Exception
配置文件未加载
Error message
配置文件未加载
What it means
PerformOptimizationWithProgress requires the XML configuration document (xmlDoc) to be loaded before it can map selected tree items to registry/service operations. If xmlDoc is null it throws "配置文件未加载". This is an internal state guard: the optimization flow was invoked before initialization finished.
Solutions
- Ensure the Config folder ships with the app and contains the expected XML file; reload the page to retry loading.
- Check earlier logs (Console.WriteLine '开始执行...' appears only after load attempt) for a swallowed XML parse failure.
- Disable the optimize/restore buttons until xmlDoc != null; enable them after loading completes.
- Await the config-load task before allowing PerformOptimizationWithProgress to run (guard in button handler).
Example fix
// before (button handler)
await PerformOptimizationWithProgress(isRestore);
// after
if (xmlDoc == null)
{
MessageBox.Show("配置仍在加载或加载失败,请稍候重试。");
return;
}
await PerformOptimizationWithProgress(isRestore); Defensive patterns
Strategy: validation
Validate before calling
if (xmlDoc == null)
{
MessageBox.Show("配置尚未加载完成,请稍候再试。");
return;
}
// or gate the UI:
buttonApply.Enabled = xmlDoc != null; Type guard
bool ConfigReady() => xmlDoc != null;
Try / catch
try { await PerformOptimizationWithProgress(isRestore); }
catch (Exception ex) when (ex.Message == "配置文件未加载")
{ MessageBox.Show("配置文件未加载,请重新打开本页面或检查 Config 目录。", "错误", MessageBoxButtons.OK, MessageBoxIcon.Error); } Prevention
- Load the XML config in the constructor and await it before wiring buttons.
- Enable action buttons only after config load succeeds.
- Fail loudly (log + UI) if the Config XML fails to parse instead of silently leaving xmlDoc null.
- Ship and verify the Config folder at startup.
When it happens
Trigger: Clicking optimize or restore while the Optimize control is still loading its XML config asynchronously, or after config loading silently failed (Config folder missing/corrupt XML), so xmlDoc was never assigned.
Common situations: User clicks apply within seconds of opening the page on slow disk; app deployed without the Config folder; XML config failed to parse during Load (exception swallowed earlier); race between async load and button enable.
Understand the failure class
Background: "X is required", "must be set", "cannot be empty": the missing-required-config error family, from Vertex AI project/location to WeChat keys — this error's family across 18 libraries.
Related errors
AI-assisted analysis of ZyperWave/ZyperWinOptimize@d20e78bbd9 (2026-09-13).
Data as JSON: /api/errors/ce89657b241f756d.
Report an issue: GitHub.
Appendix: source
Thrown at ZyperWin++/ZyperWin++/Optimize.cs:3066
// 设置分类节点的选中状态
if (allChecked && category.Sub.Count > 0)
category.Checked = true;
else if (anyChecked)
category.Checked = true; // 或者保持 indeterminate 状态
else
category.Checked = false;
}
}
// 优化或还原完成后刷新状态
private async Task PerformOptimizationWithProgress(bool isRestore)
{
Console.WriteLine($"开始执行{(isRestore ? "还原" : "优化")}操作...");
if (xmlDoc == null)
{
throw new Exception("配置文件未加载");
}
// 收集所有选中的项目
var selectedItems = new List<(string category, string itemTag, bool alreadyOptimized)>();
foreach (var category in tree1.Items)
{
foreach (var item in category.Sub)
{
if (item.Checked && item.Tag != null)
{
string itemTag = item.Tag.ToString();
bool isAlreadyOptimized = optimizationStatus.ContainsKey(itemTag) && optimizationStatus[itemTag];
// 还原操作不管是否优化过都执行
// 优化操作跳过已优化的项目
if (!isRestore && isAlreadyOptimized)
{
Console.WriteLine($"跳过已优化的项目: {itemTag}");
View on GitHub (pinned to d20e78bbd9)