{"record":{"id":"bf9d436186561993","repo":"itsfatduck/optimizerDuck","slug":"service-verify-failed-for-servicename-could-not-query-the","errorCode":null,"errorMessage":"Service verify failed for {ServiceName}: could not query the current startup type.","messagePattern":"Service verify failed for (.+?): could not query the current startup type\\.","errorType":"exception","errorClass":"StepExecutionException","httpStatus":null,"severity":"error","filePath":"optimizerDuck/Domain/Revert/Steps/ServiceRevertStep.cs","lineNumber":69,"sourceCode":"                ServiceStrings.ServiceInfoSkippedAccessDenied,\n                ServiceName\n            );\n            if (string.Equals(result.Error, accessDenied, StringComparison.Ordinal))\n                return false;\n            throw new StepExecutionException(result.Error ?? Description, result.ErrorDetail);\n        }\n\n        var (actual, notFound) = await ServiceProcessService\n            .GetStartupTypeAsync(ServiceName, opCall.Logger)\n            .ConfigureAwait(false);\n\n        // a missing service has nothing to restore.\n        if (notFound)\n            return true;\n\n        // null without NotFound means the query failed; never report an unverified restore.\n        if (actual is null)\n            throw new StepExecutionException(\n                $\"Service verify failed for {ServiceName}: could not query the current startup type.\",\n                null\n            );\n\n        if (actual.Value != OriginalStartupType)\n            throw new StepExecutionException(\n                $\"Service verify failed for {ServiceName}: expected {OriginalStartupType}, actual={actual.Value}\",\n                null\n            );\n        return true;\n    }\n\n    /// <inheritdoc />\n    public JObject ToData()\n    {\n        return new JObject\n        {\n            [nameof(ServiceName)] = ServiceName,","sourceCodeStart":51,"sourceCodeEnd":87,"githubUrl":"https://github.com/itsfatduck/optimizerDuck/blob/36acf585ae122a09f0e29eb4acedfaf94e81c0de/optimizerDuck/Domain/Revert/Steps/ServiceRevertStep.cs#L51-L87","documentation":"ServiceRevertStep.ExecuteAsync throws this when, after the restore command reported success, the follow-up query GetStartupTypeAsync returns null startup type without the NotFound flag — meaning the sc.exe qc query itself failed. The step never reports an unverified restore, so a failed verification query is a hard failure.","triggerScenarios":"Revert executed, then the verification query failed: Task/Service Control Manager temporarily unavailable, the service was deleted between the change and the query (race), timeout of the 15s query timeout, or sc.exe output not parseable due to unexpected locale/console corruption.","commonSituations":"Service removed by its updater right after the revert command ran; system under heavy load causing the 15-second query timeout; sc.exe output redirected/encoded unexpectedly.","solutions":["Retry the revert — transient SCM/timeout failures usually clear.","Verify the service still exists with sc query <ServiceName>; if deleted, the service is gone and the revert file can be discarded.","Increase AppSettings.Optimize.ShellTimeoutMs if query timeouts are the cause, then retry.","Check the Serilog log for the sc.exe stderr captured around the failure."],"exampleFix":null,"handlingStrategy":"retry","validationCode":"var (type, notFound) = await ServiceProcessService.GetStartupTypeAsync(serviceName, logger);\nif (!notFound && type is null) { /* query broken — fix environment first */ }","typeGuard":null,"tryCatchPattern":"catch (StepExecutionException ex) when (ex.Message.Contains(\"could not query the current startup type\"))\n{ await Task.Delay(2000); /* retry once */ }","preventionTips":["Avoid reverting under heavy system load or during service installs","Increase ShellTimeoutMs if queries approach the 15s timeout","Check the service was not deleted between command and verification","Run elevated so sc qc never fails on permissions"],"tags":["csharp","windows-services","sc-exe","revert","verification"],"backgroundTag":"request-timeout","analyzedSha":"36acf585ae122a09f0e29eb4acedfaf94e81c0de","analyzedAt":"2026-09-13T08:30:13.845Z","contentChangedAt":"2026-09-13T08:30:13.845Z","schemaVersion":2},"datasetVersion":"2026-09-16T04:17:20.429Z"}