AutoDarkMode/Windows-Auto-Night-Mode · error · AddAutoStartException
Auto start task could not be set.
Error message
Auto start task could not be set.
What it means
Thrown by the parameterless AddAutoStartException constructor in SettingsViewModel.AutostartRefresh when the service replies to the 'ValidateAutostart true' command with StatusCode.Err. The parameterless constructor's overridden Message always reads 'Auto start task could not be set.' ValidateAutostart asks the service to verify (and optionally repair) the autostart task registration.
Source
Thrown at AutoDarkModeApp/ViewModels/SettingsViewModel.cs:135
{
_updater.CheckNewVersion();
_dispatcherQueue.TryEnqueue(() =>
{
UpdatesDate = _updater.UpdateAvailable() ? "Msg_UpdateAvailable".GetLocalized() : "Msg_NoUpdate".GetLocalized();
});
});
}
[RelayCommand]
private async Task AutostartRefresh()
{
SetAutostartDetailsVisibility(false);
try
{
var response = ApiResponse.FromString(await MessageHandler.Client.SendMessageAndGetReplyAsync($"{Command.ValidateAutostart} true", 2));
if (response.StatusCode == StatusCode.Err)
{
throw new AddAutoStartException();
}
await GetAutostartInfo();
}
catch (Exception)
{
throw new AddAutoStartException($"Could not validate autostart", "ValidateAutostart");
}
await Task.Delay(fakeResponsiveUIDelay);
SetAutostartDetailsVisibility(true);
}
public SettingsViewModel(IErrorService errorService, ILocalSettingsService localSettingsService)
{
_dispatcherQueue = Microsoft.UI.Dispatching.DispatcherQueue.GetForCurrentThread();
_updater = new();
_errorService = errorService;
_localSettingsService = localSettingsService;
View on GitHub (pinned to c15b28e921)
Solutions
- Ensure AutoDarkModeSvc is running and responsive before triggering AutostartRefresh.
- Increase the short 2-second reply timeout if the validation is slow under load.
- Recreate the autostart task: disable then re-enable autostart in Settings.
- Check Task Scheduler for the AutoDarkMode task and its last run result.
Defensive patterns
Strategy: try-catch
Validate before calling
// Validate the service reply timeout is adequate before calling ValidateAutostart
public static async Task<bool> CanValidateAutostartAsync(int timeoutSeconds)
{
try
{
var r = ApiResponse.FromString(await MessageHandler.Client.SendMessageAndGetReplyAsync($"{Command.ValidateAutostart} true", timeoutSeconds));
return r.StatusCode != StatusCode.Err;
}
catch { return false; }
} Try / catch
// AutostartRefresh is a [RelayCommand]; the AddAutoStartException propagates to
// the command infrastructure. Wrap the command body or subscribe to errors:
try { await AutostartRefresh(); }
catch (AddAutoStartException) { /* notify user, keep UI consistent */ } Prevention
- Ensure the service is responsive before triggering validation.
- Use a timeout longer than 2 seconds on slow or busy machines.
- Pre-check Task Scheduler for a valid AutoDarkMode task.
- Treat a validation failure as recoverable: offer a re-create action in the UI.
When it happens
Trigger: AutostartRefresh [RelayCommand] sends $"{Command.ValidateAutostart} true" with a 2-second timeout. ApiResponse.FromString(...).StatusCode == 'Err'. The AddAutoStartException() is thrown at line 135 and then caught by the catch-all at line 139 which re-wraps it.
Common situations: The autostart task is missing or corrupt in Task Scheduler; the service cannot validate the task because of privilege issues; the 2-second timeout is too short on a slow/busy machine so the service returns Err; the service is not running.
Related errors
- Could not add Auto Dark Mode to autostart
- Theme switching is unsuccessful: {result}
- Theme switching is unsuccessful: {result}
- Theme switching is unsuccessful: {result}
- Theme switching is unsuccessful: {result}
AI-assisted analysis of AutoDarkMode/Windows-Auto-Night-Mode@c15b28e921 (2026-08-13).
Data as JSON: /api/errors/6ef613191cc88ca9.
Report an issue: GitHub.