AutoDarkMode/Windows-Auto-Night-Mode · warning · SwitchThemeException
Theme switching is unsuccessful: Couldn't clean up monitor l
Error message
Theme switching is unsuccessful: Couldn't clean up monitor list, {result} What it means
Thrown in WallpaperPickerPage.RemoveDisconnectedMonitorsHyperlinkButton_Click when the reply to Command.CleanMonitors is not Ok. SwitchThemeException is reused with an explicit message 'Couldn't clean up monitor list, {result}', producing 'Theme switching is unsuccessful: Couldn't clean up monitor list, {result}'. The double prefix is misleading — CleanMonitors is unrelated to theme switching. Caught locally; an inner try/catch also guards _builder.Load().
Source
Thrown at AutoDarkModeApp/Views/WallpaperPickerPage.xaml.cs:111
if (result != StatusCode.Ok)
{
throw new SwitchThemeException(result, "WallpaperPickerPage");
}
}
catch (Exception ex)
{
await _errorService.ShowErrorMessage(ex, App.MainWindow.Content.XamlRoot, "WallpaperPickerPage");
}
}
private async void RemoveDisconnectedMonitorsHyperlinkButton_Click(object sender, RoutedEventArgs e)
{
try
{
string result = await MessageHandler.Client.SendMessageAndGetReplyAsync(Command.CleanMonitors);
if (result != StatusCode.Ok)
{
throw new SwitchThemeException($"Couldn't clean up monitor list, {result}", "WallpaperPickerPage");
}
try
{
_builder.Load();
List<MonitorSettings> monitors = _builder.Config.WallpaperSwitch.Component.Monitors;
MonitorsComboBox.ItemsSource = monitors;
MonitorsComboBox.SelectedItem = monitors.FirstOrDefault();
}
catch (Exception ex)
{
await _errorService.ShowErrorMessage(ex, App.MainWindow.Content.XamlRoot, "CleanMonitors");
}
}
catch (Exception ex)
{
await _errorService.ShowErrorMessage(ex, App.MainWindow.Content.XamlRoot, "CleanMonitors");
}
}View on GitHub (pinned to c15b28e921)
Solutions
- Re-run DetectMonitors to refresh state, then retry cleanup.
- Ensure the service is running and check its log.
- Manually reconcile the monitor list in config if cleanup keeps failing.
- Use a more appropriate exception type (not SwitchThemeException) so the message is not prefixed with 'Theme switching is unsuccessful'.
Example fix
// before — reuses SwitchThemeException producing a misleading double prefix
if (result != StatusCode.Ok)
throw new SwitchThemeException($"Couldn't clean up monitor list, {result}", "WallpaperPickerPage");
// after — use a domain-appropriate exception
if (result != StatusCode.Ok)
throw new InvalidOperationException($"Couldn't clean up monitor list: {result}"); Defensive patterns
Strategy: try-catch
Validate before calling
// Re-detect monitors before cleanup so the list is current
public static async Task<bool> RefreshedBeforeCleanAsync()
{
try { var r = await MessageHandler.Client.SendMessageAndGetReplyAsync(Command.DetectMonitors); return r == StatusCode.Ok; }
catch { return false; }
} Try / catch
// RemoveDisconnectedMonitorsHyperlinkButton_Click already try/catches.
// Replace SwitchThemeException with a clearer type so the message is not
// prefixed with 'Theme switching is unsuccessful':
catch (InvalidOperationException ex) { await _errorService.ShowErrorMessage(ex, App.MainWindow.Content.XamlRoot, "CleanMonitors"); } Prevention
- Use a domain-appropriate exception for monitor cleanup, not SwitchThemeException.
- Refresh monitor state (DetectMonitors) before offering cleanup.
- Handle the inner _builder.Load() failure separately from the CleanMonitors failure.
- Check the service log when cleanup repeatedly fails.
When it happens
Trigger: User clicks the 'remove disconnected monitors' hyperlink. SendMessageAndGetReplyAsync(Command.CleanMonitors) returns != 'Ok'. The throw at line 111 is caught by the outer catch.
Common situations: Service cannot prune the monitor list (e.g. monitors reconnected between detection and cleanup); service returned Err; the clean operation partially failed; service not running.
Related errors
- Theme switching is unsuccessful: {result}
- 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/c57db822cbccdf8c.
Report an issue: GitHub.