{"record":{"id":"7e3be7601d807e85","repo":"memstechtips/Winhance","slug":"configuration-file-is-invalid-or-corrupted","errorCode":null,"errorMessage":"Configuration file is invalid or corrupted.","messagePattern":"Configuration file is invalid or corrupted\\.","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"src/Winhance.Infrastructure/Features/Common/Services/ConfigurationApplicationBridgeService.cs","lineNumber":142,"sourceCode":"            return item.SelectedIndex.Value;\r\n        }\r\n\r\n        return 0;\r\n    }\r\n\r\n    private object ResolvePowerPlanValue(SettingDefinition setting, ConfigurationItem item)\r\n    {\r\n        if (!string.IsNullOrEmpty(item.PowerPlanGuid))\r\n        {\r\n            return new Dictionary<string, object>\r\n            {\r\n                [\"Guid\"] = item.PowerPlanGuid,\r\n                [\"Name\"] = item.PowerPlanName ?? \"Unknown\"\r\n            };\r\n        }\r\n\r\n        _logService.Log(LogLevel.Error, \"Config file is missing PowerPlanGuid for power-plan-selection.\");\r\n        throw new InvalidOperationException(\"Configuration file is invalid or corrupted.\");\r\n    }\r\n\r\n    private object? ResolveNumericRangeValue(SettingDefinition setting, ConfigurationItem item)\r\n    {\r\n        if (item.PowerSettings == null || item.PowerSettings.Count == 0)\r\n            return null;\r\n\r\n        // PowerCfg-backed NumericRange settings are exported in SYSTEM units (raw powercfg\r\n        // reads, e.g. seconds). PowerCfgApplier treats incoming dict/scalar values as DISPLAY\r\n        // units and converts display→system itself, so we must convert system→display here —\r\n        // exactly as RecommendedSettingsResolver.BuildPowerCfgApplyValue does for the manual\r\n        // quick-set path. Non-PowerCfg NumericRange settings carry no PowerCfgSettings and pass\r\n        // through unchanged.\r\n        bool isPowerCfg = setting.PowerCfgSettings?.Any() == true;\r\n        string? displayUnits = isPowerCfg ? RecommendedSettingsResolver.GetPowerCfgDisplayUnits(setting) : null;\r\n\r\n        var hasAcValue = item.PowerSettings.TryGetValue(\"ACValue\", out var acVal);\r\n        var hasDcValue = item.PowerSettings.TryGetValue(\"DCValue\", out var dcVal);\r","sourceCodeStart":124,"sourceCodeEnd":160,"githubUrl":"https://github.com/memstechtips/Winhance/blob/f23d554eb2d6400b1827bcc46b91294ffa53fbc9/src/Winhance.Infrastructure/Features/Common/Services/ConfigurationApplicationBridgeService.cs#L124-L160","documentation":"InvalidOperationException thrown by ResolvePowerPlanValue when applying a configuration: a setting of kind power-plan-selection was selected, but the ConfigurationItem carried no PowerPlanGuid. The resolver cannot build a power-plan value without a GUID, so it treats the config file as corrupted. The message is generic even though the cause is specific (logged separately).","triggerScenarios":"ApplyConfigurationAsync encounters a ConfigurationItem whose SettingDefinition is power-plan-selection but PowerPlanGuid is null/empty. This happens when the exported/imported config file omitted the Guid field for that power plan entry, or the schema changed and the field was renamed/dropped during serialization.","commonSituations":"User hand-edited a saved config JSON and removed the Guid. An older Winhance version exported power plans without a Guid field. A config import from another machine references a power plan GUID that was not serialized. The UI created a power-plan-selection item without resolving the GUID.","solutions":["Open the config file and confirm each power-plan-selection item has a non-empty PowerPlanGuid (and ideally PowerPlanName).","Re-export the configuration from a working Winhance install rather than hand-editing.","If the plan is a built-in one, fill the well-known GUID: Balanced = 381b4222-f694-41f0-9685-ff5bb260df2e, High performance = 8c5e7fda-e8bf-4a96-9a85-a6e23a8c635c, Power saver = a1841308-3541-4fab-bc81-f71556f20b4a.","Improve the error message to name the offending item and the missing field so the user can fix it directly."],"exampleFix":"// before\n_logService.Log(LogLevel.Error, \"Config file is missing PowerPlanGuid for power-plan-selection.\");\nthrow new InvalidOperationException(\"Configuration file is invalid or corrupted.\");\n\n// after: name the item so the user can fix the specific entry\nthrow new InvalidOperationException(\n    $\"Configuration item '{item.SettingId ?? item.Name}' is a power-plan-selection but has no PowerPlanGuid. \" +\n    \"Set PowerPlanGuid (and PowerPlanName) in the config file and retry.\");","handlingStrategy":"validation","validationCode":"// Validate the config item before applying.\nbool IsValidPowerPlanItem(ConfigurationItem item) =>\n    !string.IsNullOrEmpty(item.PowerPlanGuid);","typeGuard":null,"tryCatchPattern":"catch (InvalidOperationException ex) when (ex.Message.Contains(\"Configuration file is invalid or corrupted\"))\n{\n    // Tell the user a power-plan-selection item is missing its Guid; offer to skip that item or re-export config.\n}","preventionTips":["Re-export configs from a working Winhance install rather than hand-editing.","Validate every power-plan-selection item has a non-empty Guid on import.","Keep the well-known built-in plan GUIDs documented for manual repair."],"tags":["configuration","validation","power-plan","windows","data-integrity"],"backgroundTag":null,"analyzedSha":"f23d554eb2d6400b1827bcc46b91294ffa53fbc9","analyzedAt":"2026-08-13T17:55:20.922Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}