AutoDarkMode/Windows-Auto-Night-Mode · warning · SwitchThemeException
Theme switching is unsuccessful: {result}
Error message
Theme switching is unsuccessful: {result} What it means
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.
Source
Thrown at AutoDarkModeApp/Views/WallpaperPickerPage.xaml.cs:37
InitializeComponent();
Loaded += WallpaperPickerPage_Loaded;
}
private async void WallpaperPickerPage_Loaded(object sender, RoutedEventArgs e)
{
await DetectMonitorsAsync();
LoadMonitors();
}
private async Task DetectMonitorsAsync()
{
try
{
string result = await MessageHandler.Client.SendMessageAndGetReplyAsync(Command.DetectMonitors);
if (result != StatusCode.Ok)
{
throw new SwitchThemeException(result, "WallpaperPickerPage");
}
try
{
_builder.Load();
}
catch (Exception ex)
{
await _errorService.ShowErrorMessage(ex, App.MainWindow.Content.XamlRoot, "Constructor");
}
}
catch (Exception ex)
{
await _errorService.ShowErrorMessage(ex, App.MainWindow.Content.XamlRoot, "Constructor");
}
}
private void LoadMonitors()View on GitHub (pinned to c15b28e921)
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).
Defensive patterns
Strategy: try-catch
Validate before calling
// Confirm the service is up before navigating to the Wallpaper page
public static async Task<bool> IsServiceUpAsync()
{
try { await MessageHandler.Client.SendMessageAndGetReplyAsync(Command.DetectMonitors); return true; }
catch { return false; }
} Try / catch
// DetectMonitorsAsync already wraps in try/catch routing to _errorService. // Refactor async void -> Task so the caller can decide to retry or skip monitor load.
Prevention
- 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.
When it happens
Trigger: WallpaperPickerPage loads (OnNavigatedTo -> DetectMonitorsAsync). SendMessageAndGetReplyAsync(Command.DetectMonitors) returns != 'Ok'. The throw at line 37 is caught at the method's outer catch.
Common situations: Service cannot enumerate display monitors; monitor configuration changed during detection; service not running or returned Err; no reply within the default timeout.
Related errors
- Theme switching is unsuccessful: Couldn't clean up monitor l
- Theme switching is unsuccessful: {result}
- Could not add Auto Dark Mode to autostart
- Auto start task could not be set.
- Theme switching is unsuccessful: {result}
AI-assisted analysis of AutoDarkMode/Windows-Auto-Night-Mode@c15b28e921 (2026-08-13).
Data as JSON: /api/errors/b07e761c2a37c1e9.
Report an issue: GitHub.