{"record":{"id":"f91a2b7b48ff2d18","repo":"AutoDarkMode/Windows-Auto-Night-Mode","slug":"theme-switching-is-unsuccessful-result-f91a2b","errorCode":null,"errorMessage":"Theme switching is unsuccessful: {result}","messagePattern":"Theme switching is unsuccessful: (.+?)","errorType":"exception","errorClass":"SwitchThemeException","httpStatus":null,"severity":"warning","filePath":"AutoDarkModeApp/ViewModels/SystemAreasViewModel.cs","lineNumber":189,"sourceCode":"    {\r\n        StateUpdateHandler.StopConfigWatcher();\r\n        _dispatcherQueue.TryEnqueue(() =>\r\n        {\r\n            _builder.Load();\r\n            LoadSettings();\r\n        });\r\n        StateUpdateHandler.StartConfigWatcher();\r\n    }\r\n\r\n    // TODO: Different processing methods from TimeViewModel\r\n    private async void RequestThemeSwitch()\r\n    {\r\n        try\r\n        {\r\n            var result = await MessageHandler.Client.SendMessageAndGetReplyAsync(Command.RequestSwitch, 15);\r\n            if (result != StatusCode.Ok)\r\n            {\r\n                throw new SwitchThemeException(result, \"SystemAreasViewModel\");\r\n            }\r\n        }\r\n        catch (Exception ex)\r\n        {\r\n            await _errorService.ShowErrorMessage(ex, App.MainWindow.Content.XamlRoot, \"SystemAreasViewModel\");\r\n        }\r\n    }\r\n\r\n    partial void OnAppsSwitchComponentModeChanged(AppSwitchMode value)\r\n    {\r\n        if (_isInitializing)\r\n            return;\r\n\r\n        if (value != AppSwitchMode.Disabled)\r\n        {\r\n            _builder.Config.AppsSwitch.Enabled = true;\r\n            _builder.Config.AppsSwitch.Component.Mode = value switch\r\n            {\r","sourceCodeStart":171,"sourceCodeEnd":207,"githubUrl":"https://github.com/AutoDarkMode/Windows-Auto-Night-Mode/blob/c15b28e92138a1baff6165bbca80842f06cb819f/AutoDarkModeApp/ViewModels/SystemAreasViewModel.cs#L171-L207","documentation":"Same RequestThemeSwitch pattern in SystemAreasViewModel. Thrown when Command.RequestSwitch reply != Ok; Source='SystemAreasViewModel'. The method comment 'TODO: Different processing methods from TimeViewModel' signals known divergence. Caught locally and shown via IErrorService.","triggerScenarios":"SystemAreasViewModel.RequestThemeSwitch() runs (after a system-areas setting change). Reply to RequestSwitch (15s) != 'Ok'.","commonSituations":"A system-area component (taskbar, registry-based theme area) failed to apply; service returned Err with details; privilege issues writing to system theme registry keys; timeout.","solutions":["Confirm AutoDarkModeSvc has the privileges needed for system-area changes.","Check the service log for which system area failed.","Retry after ensuring no other theme-changing process is active.","Verify the 15s timeout is adequate for multi-area switches."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"// Pre-check that system-area registry keys are writable by the service context\npublic static bool CanWriteSystemAreas() =>\n    System.Security.Principal.WindowsIdentity.GetCurrent().Owner != null; // run elevated if needed","typeGuard":null,"tryCatchPattern":"// Already caught and routed to ShowErrorMessage. Refactor async void -> Task\n// if the caller needs to observe the SwitchThemeException.","preventionTips":["Run the service with privileges sufficient for system-area registry writes.","Close competing personalization/theme tools before switching.","Resolve the TODO (divergence from TimeViewModel) to standardize processing.","Check the service log for the specific system area that failed."],"tags":["theme-switch","ipc","named-pipe","system-areas"],"backgroundTag":null,"analyzedSha":"c15b28e92138a1baff6165bbca80842f06cb819f","analyzedAt":"2026-08-13T21:04:56.049Z","schemaVersion":2},"datasetVersion":"2026-08-14T00:17:13.853Z"}