{"record":{"id":"1ea45aede65805a1","repo":"Devolutions/UniGetUI","slug":"provide-exactly-one-of-enabled-or-value-when-setti","errorCode":null,"errorMessage":"Provide exactly one of enabled or value when setting a setting.","messagePattern":"Provide exactly one of enabled or value when setting a setting\\.","errorType":"validation","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"src/UniGetUI.Interface.IpcApi/IpcManagerSettingsApi.cs","lineNumber":165,"sourceCode":"            .ToArray();\n    }\n\n    public static IpcSettingInfo GetSetting(string settingKey)\n    {\n        return ToSettingInfo(ResolveSettingKey(settingKey));\n    }\n\n    public static IpcSettingInfo SetSetting(IpcSettingValueRequest request)\n    {\n        ArgumentNullException.ThrowIfNull(request);\n\n        var key = ResolveSettingKey(request.SettingKey);\n        var hasEnabled = request.Enabled.HasValue;\n        var hasValue = request.Value is not null;\n\n        if (hasEnabled == hasValue)\n        {\n            throw new InvalidOperationException(\n                \"Provide exactly one of enabled or value when setting a setting.\"\n            );\n        }\n\n        if (hasValue)\n        {\n            Settings.SetValue(key, request.Value ?? \"\");\n        }\n        else\n        {\n            Settings.Set(key, request.Enabled!.Value);\n        }\n\n        return ToSettingInfo(key);\n    }\n\n    public static IpcSettingInfo ClearSetting(string settingKey)\n    {","sourceCodeStart":147,"sourceCodeEnd":183,"githubUrl":"https://github.com/Devolutions/UniGetUI/blob/9b1d7d0eab91620fc15c86b36676532095936ae3/src/UniGetUI.Interface.IpcApi/IpcManagerSettingsApi.cs#L147-L183","documentation":"Thrown by SetSetting when the caller provides both Enabled and Value, or neither, on the IpcSettingValueRequest. The API is designed as a discriminated union: boolean settings use Settings.Set (file existence) and string settings use Settings.SetValue (file content). The check hasEnabled == hasValue catches both the both-set and neither-set cases simultaneously.","triggerScenarios":"Calling SetSetting with an IpcSettingValueRequest where Enabled.HasValue and Value is not null (both provided), or where Enabled is null and Value is null (neither provided). The XOR condition must be satisfied: exactly one must be present.","commonSituations":"IPC client sends a JSON payload with both fields populated (common when a UI form sends all fields). Client omits both fields entirely (default JSON deserialization gives null for both). Misunderstanding the API contract — thinking Enabled is a read-only response field rather than a write input.","solutions":["For boolean settings: set Enabled to true/false and leave Value null.","For string settings: set Value to the desired string and leave Enabled null.","Inspect the setting type via ListSettings() — if IsSet/BoolValue semantics apply, use Enabled; if StringValue/HasStringValue apply, use Value."],"exampleFix":"// before — ambiguous request\nvar req = new IpcSettingValueRequest {\n    SettingKey = \"EnableScoopCleanup\",\n    Enabled = true,\n    Value = \"true\"  // ambiguous!\n};\n// after — boolean setting\nvar req = new IpcSettingValueRequest {\n    SettingKey = \"EnableScoopCleanup\",\n    Enabled = true\n    // Value left null\n};","handlingStrategy":"validation","validationCode":"static void ValidateSettingRequest(IpcSettingValueRequest req)\n{\n    var hasEnabled = req.Enabled.HasValue;\n    var hasValue = req.Value is not null;\n    if (hasEnabled == hasValue)\n        throw new ArgumentException(\"Provide exactly one of Enabled or Value.\");\n}\n\nValidateSettingRequest(request);","typeGuard":null,"tryCatchPattern":null,"preventionTips":["For boolean settings: set Enabled, leave Value null.","For string settings: set Value, leave Enabled null.","Never send both fields — the XOR check rejects it.","Check ListSettings() to see which settings are boolean vs string."],"tags":["settings","ipc","validation","api-contract"],"backgroundTag":null,"analyzedSha":"9b1d7d0eab91620fc15c86b36676532095936ae3","analyzedAt":"2026-08-13T12:19:18.278Z","schemaVersion":2},"datasetVersion":"2026-08-13T14:17:21.547Z"}