{"record":{"id":"cc80595f91e7eba8","repo":"itsfatduck/optimizerDuck","slug":"registry-verify-failed-at-path-expected-key-to-exist-but-it","errorCode":null,"errorMessage":"Registry verify failed at {Path}: expected key to exist, but it was missing","messagePattern":"Registry verify failed at (.+?): expected key to exist, but it was missing","errorType":"exception","errorClass":"StepExecutionException","httpStatus":null,"severity":"error","filePath":"optimizerDuck/Domain/Revert/Steps/RegistryRevertStep.cs","lineNumber":305,"sourceCode":"                        $\"Registry verify failed at {Path}:{Name}: expected '<absent>', actual '{actual}'\",\n                        null\n                    );\n                break;\n            }\n            case RevertAction.RestoreKey:\n                if (\n                    !RegistryService.TryKeyExists(\n                        new RegistryItem(Path),\n                        out var restoreExists,\n                        call.Logger\n                    )\n                )\n                    throw new StepExecutionException(\n                        $\"Registry verify failed at {Path}: could not query the key.\",\n                        null\n                    );\n                if (!restoreExists)\n                    throw new StepExecutionException(\n                        $\"Registry verify failed at {Path}: expected key to exist, but it was missing\",\n                        null\n                    );\n                break;\n            case RevertAction.DeleteKey:\n                if (\n                    !RegistryService.TryKeyExists(\n                        new RegistryItem(Path),\n                        out var deleteExists,\n                        call.Logger\n                    )\n                )\n                    throw new StepExecutionException(\n                        $\"Registry verify failed at {Path}: could not query the key.\",\n                        null\n                    );\n                if (deleteExists)\n                    throw new StepExecutionException(","sourceCodeStart":287,"sourceCodeEnd":323,"githubUrl":"https://github.com/itsfatduck/optimizerDuck/blob/36acf585ae122a09f0e29eb4acedfaf94e81c0de/optimizerDuck/Domain/Revert/Steps/RegistryRevertStep.cs#L287-L323","documentation":"Post-revert verification failure in RegistryRevertStep.VerifyRestore for a RestoreKey action: after restoring a deleted key tree, the code re-checks registry existence via RegistryService.TryKeyExists and the key that should have been recreated is still missing. This means the restore operation reported success but its effect is not observable in the registry — typically because the restore write silently failed, was rolled back, or another process removed the key between restore and verify. Fail-closed: the step refuses to claim success it cannot confirm.","triggerScenarios":"CreateSubKey(Path) returned Ok, but TryKeyExists(Path) finds no key: the key was deleted between create and verify, or the write landed in a different registry view (WOW64 redirection) than the one queried.","commonSituations":"Another process or cleanup routine removing the freshly created key; 32-bit vs 64-bit view mismatch (CreateSubKey wrote to WOW6432Node while verify checks the 64-bit path); virtualization (registry virtualization for non-elevated writes) silently redirecting the key.","solutions":["Re-run the revert elevated to avoid registry virtualization redirection.","Check whether the key exists under WOW6432Node and correct the stored Path.","Find what deleted the key (Process Monitor) and stop it before reverting.","Recreate the key manually and delete the revert file."],"exampleFix":"// before\nif (!restoreExists)\n    throw new StepExecutionException($\"Registry verify failed at {Path}: expected key to exist, but it was missing\", null);\n// after: recreate once before failing\nif (!restoreExists)\n{\n    RegistryService.CreateSubKey(opCall, new RegistryItem(Path));\n    RegistryService.TryKeyExists(new RegistryItem(Path), out restoreExists, call.Logger);\n    if (!restoreExists) throw new StepExecutionException($\"...expected key to exist, but it was missing\", null);\n}","handlingStrategy":"retry","validationCode":"// check both views before concluding the key is missing\nbool exists64 = RegistryService.KeyExists(new RegistryItem(path));\nbool exists32 = RegistryService.KeyExists(new RegistryItem(path.Replace(\"\\\\Software\\\\\", \"\\\\Software\\\\WOW6432Node\\\\\")));","typeGuard":"bool IsKeyRestoreMissing(StepExecutionException ex) => ex.Message.Contains(\"expected key to exist, but it was missing\");","tryCatchPattern":"try { await step.ExecuteAsync(shell, logger); }\ncatch (StepExecutionException ex) when (ex.Message.Contains(\"it was missing\"))\n{\n    logger.LogWarning(\"Key vanished after create; retrying restore once\");\n    await step.ExecuteAsync(shell, logger);\n}","preventionTips":["Run elevated to avoid registry virtualization redirecting CreateSubKey.","Confirm bitness consistency between the applying process and verification.","Investigate cleanup tools/AV that remove freshly created keys."],"tags":["registry","verify","revert","key-missing"],"backgroundTag":"resource-not-found","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"}