{"record":{"id":"b07e761c2a37c1e9","repo":"AutoDarkMode/Windows-Auto-Night-Mode","slug":"theme-switching-is-unsuccessful-result-b07e76","errorCode":null,"errorMessage":"Theme switching is unsuccessful: {result}","messagePattern":"Theme switching is unsuccessful: (.+?)","errorType":"exception","errorClass":"SwitchThemeException","httpStatus":null,"severity":"warning","filePath":"AutoDarkModeApp/Views/WallpaperPickerPage.xaml.cs","lineNumber":37,"sourceCode":"        InitializeComponent();\n        Loaded += WallpaperPickerPage_Loaded;\n    }\n\n    private async void WallpaperPickerPage_Loaded(object sender, RoutedEventArgs e)\n    {\n        await DetectMonitorsAsync();\n        LoadMonitors();\n    }\n\n\n    private async Task DetectMonitorsAsync()\n    {\n        try\n        {\n            string result = await MessageHandler.Client.SendMessageAndGetReplyAsync(Command.DetectMonitors);\n            if (result != StatusCode.Ok)\n            {\n                throw new SwitchThemeException(result, \"WallpaperPickerPage\");\n            }\n            try\n            {\n                _builder.Load();\n            }\n            catch (Exception ex)\n            {\n                await _errorService.ShowErrorMessage(ex, App.MainWindow.Content.XamlRoot, \"Constructor\");\n            }\n        }\n        catch (Exception ex)\n        {\n            await _errorService.ShowErrorMessage(ex, App.MainWindow.Content.XamlRoot, \"Constructor\");\n        }\n    }\n\n\n    private void LoadMonitors()","sourceCodeStart":19,"sourceCodeEnd":55,"githubUrl":"https://github.com/AutoDarkMode/Windows-Auto-Night-Mode/blob/c15b28e92138a1baff6165bbca80842f06cb819f/AutoDarkModeApp/Views/WallpaperPickerPage.xaml.cs#L19-L55","documentation":"Thrown in WallpaperPickerPage.DetectMonitorsAsync when the reply to Command.DetectMonitors is not StatusCode.Ok. Unlike errors 7-11 this is NOT RequestSwitch — it is the monitor-detection command. SwitchThemeException is (arguably mis-) reused here, carrying Source='WallpaperPickerPage'. The message becomes 'Theme switching is unsuccessful: {result}'. It is caught by the outer catch in DetectMonitorsAsync.","triggerScenarios":"WallpaperPickerPage loads (OnNavigatedTo -> DetectMonitorsAsync). SendMessageAndGetReplyAsync(Command.DetectMonitors) returns != 'Ok'. The throw at line 37 is caught at the method's outer catch.","commonSituations":"Service cannot enumerate display monitors; monitor configuration changed during detection; service not running or returned Err; no reply within the default timeout.","solutions":["Ensure AutoDarkModeSvc is running before opening the Wallpaper page.","Trigger a monitor re-detection after the display configuration stabilizes.","Check the service log for the monitor-detection failure reason.","Verify the display driver/OS is not mid mode-change (sleep, dock hot-plug)."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"// Confirm the service is up before navigating to the Wallpaper page\npublic static async Task<bool> IsServiceUpAsync()\n{\n    try { await MessageHandler.Client.SendMessageAndGetReplyAsync(Command.DetectMonitors); return true; }\n    catch { return false; }\n}","typeGuard":null,"tryCatchPattern":"// DetectMonitorsAsync already wraps in try/catch routing to _errorService.\n// Refactor async void -> Task so the caller can decide to retry or skip monitor load.","preventionTips":["Ensure the service is running before opening the Wallpaper page.","Avoid navigating to the page during display mode changes (sleep, dock hot-plug).","Use a domain-specific exception instead of SwitchThemeException for monitor detection.","Retry detection after the display configuration stabilizes."],"tags":["monitor-detection","ipc","named-pipe","wallpaper","misused-exception"],"backgroundTag":null,"analyzedSha":"c15b28e92138a1baff6165bbca80842f06cb819f","analyzedAt":"2026-08-13T21:04:56.049Z","schemaVersion":2},"datasetVersion":"2026-08-14T00:17:13.853Z"}