{"record":{"id":"acb285e4cc89e325","repo":"AutoDarkMode/Windows-Auto-Night-Mode","slug":"theme-switching-is-unsuccessful-result","errorCode":null,"errorMessage":"Theme switching is unsuccessful: {result}","messagePattern":"Theme switching is unsuccessful: (.+?)","errorType":"exception","errorClass":"SwitchThemeException","httpStatus":null,"severity":"warning","filePath":"AutoDarkModeApp/ViewModels/ColorizationViewModel.cs","lineNumber":71,"sourceCode":"        try\n        {\n            _skipConfigUpdate = true;\n            _builder.Save();\n        }\n        catch (Exception ex)\n        {\n            _errorService.ShowErrorMessage(ex, App.MainWindow.Content.XamlRoot, \"ColorizationViewModel\");\n        }\n    }\n\n    public async void RequestThemeSwitch()\n    {\n        try\n        {\n            var result = await MessageHandler.Client.SendMessageAndGetReplyAsync(Command.RequestSwitch, 15);\n            if (result != StatusCode.Ok)\n            {\n                throw new SwitchThemeException(result, \"ColorizationViewModel\");\n            }\n        }\n        catch (Exception ex)\n        {\n            await _errorService.ShowErrorMessage(ex, App.MainWindow.Content.XamlRoot, \"ColorizationViewModel\");\n        }\n    }\n\n    public ColorizationViewModel(IErrorService errorService)\n    {\n        _dispatcherQueue = Microsoft.UI.Dispatching.DispatcherQueue.GetForCurrentThread();\n        _errorService = errorService;\n\n        try\n        {\n            _builder.Load();\n        }\n        catch (Exception ex)","sourceCodeStart":53,"sourceCodeEnd":89,"githubUrl":"https://github.com/AutoDarkMode/Windows-Auto-Night-Mode/blob/c15b28e92138a1baff6165bbca80842f06cb819f/AutoDarkModeApp/ViewModels/ColorizationViewModel.cs#L53-L89","documentation":"Thrown by ColorizationViewModel.RequestThemeSwitch when the service reply to Command.RequestSwitch (with a 15-second timeout) is not StatusCode.Ok. SwitchThemeException formats the message as 'Theme switching is unsuccessful: {result}' where {result} is the raw status string returned. The method is async-void and already wraps everything in try/catch that routes to IErrorService.ShowErrorMessage.","triggerScenarios":"ColorizationViewModel.RequestThemeSwitch() is called (e.g. after a colorization setting change). SendMessageAndGetReplyAsync(Command.RequestSwitch, 15) returns a value != 'Ok' (e.g. 'Err', 'Timeout', or an error detail string). The exception is thrown and immediately caught by the surrounding catch.","commonSituations":"Service is busy or the theme switch component failed; the 15s timeout elapsed and the reply is 'Timeout'; the service returned an error detail because a sub-component (apps, wallpaper, system) failed to apply; service not running.","solutions":["Check that AutoDarkModeSvc is running and responsive.","Review the service log for the specific component that failed during the switch.","Retry the theme switch after a brief delay (transient component lock).","Increase or verify the 15-second timeout is sufficient for slow systems."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"// Best-effort pre-check that the service can switch before requesting\npublic static async Task<bool> CanSwitchAsync()\n{\n    try { var r = await MessageHandler.Client.SendMessageAndGetReplyAsync(Command.RequestSwitch, 15); return r == StatusCode.Ok; }\n    catch { return false; }\n}","typeGuard":null,"tryCatchPattern":"// RequestThemeSwitch already catches and routes to _errorService.\n// Callers need not wrap it (async-void), but should react to the error dialog.\n// To make it observable, refactor to Task and await:\n// private async Task RequestThemeSwitchAsync() { try {...} catch {...} }","preventionTips":["Ensure the service is idle before requesting a switch (avoid overlapping switches).","Review the service log when a non-Ok status appears.","Keep the 15s timeout adequate for the slowest target system.","Debounce rapid setting changes so multiple switches do not queue/collide."],"tags":["theme-switch","ipc","named-pipe","colorization"],"backgroundTag":null,"analyzedSha":"c15b28e92138a1baff6165bbca80842f06cb819f","analyzedAt":"2026-08-13T21:04:56.049Z","schemaVersion":2},"datasetVersion":"2026-08-14T00:17:13.853Z"}