{"record":{"id":"e096822e53bb9bb6","repo":"Tichau/FileConverter","slug":"can-t-retrieve-file-converter-registry-entry","errorCode":null,"errorMessage":"Can't retrieve file converter registry entry.","messagePattern":"Can't retrieve file converter registry entry\\.","errorType":"exception","errorClass":"Exception","httpStatus":null,"severity":"error","filePath":"Application/FileConverterExtension/PathHelpers.cs","lineNumber":39,"sourceCode":"                if (string.IsNullOrEmpty(pathToFileConverterExecutable))\n                {\n                    return null;\n                }\n\n                return Path.Combine(Path.GetDirectoryName(pathToFileConverterExecutable), \"Settings.default.xml\");\n            }\n        }\n\n        public static RegistryKey FileConverterRegistryKey\n        {\n            get\n            {\n                if (PathHelpers.fileConverterRegistryKey == null)\n                {\n                    PathHelpers.fileConverterRegistryKey = Registry.CurrentUser.OpenSubKey(@\"Software\\FileConverter\");\n                    if (PathHelpers.fileConverterRegistryKey == null)\n                    {\n                        throw new Exception(\"Can't retrieve file converter registry entry.\");\n                    }\n                }\n\n                return PathHelpers.fileConverterRegistryKey;\n            }\n        }\n\n        public static string FileConverterPath\n        {\n            get\n            {\n                if (string.IsNullOrEmpty(PathHelpers.fileConverterPath))\n                {\n                    PathHelpers.fileConverterPath = PathHelpers.FileConverterRegistryKey.GetValue(\"Path\") as string;\n                }\n\n                return PathHelpers.fileConverterPath;\n            }","sourceCodeStart":21,"sourceCodeEnd":57,"githubUrl":"https://github.com/Tichau/FileConverter/blob/6c157a411fb70fb7440d2e3b226042781fd55b15/Application/FileConverterExtension/PathHelpers.cs#L21-L57","documentation":"PathHelpers.FileConverterRegistryKey (FileConverterExtension project) throws Exception when Registry.CurrentUser.OpenSubKey(@\"Software\\FileConverter\") returns null — i.e. the HKCU\\Software\\FileConverter key does not exist for the current user. The shell extension reads this key (and its 'Path' string value via FileConverterPath) to locate the installed FileConverter.exe, so the throw means the host application is not registered for this user. Because it is a plain throw in a static property getter, any caller that touches FileConverterRegistryKey, FileConverterPath or DefaultSettingsFilePath will propagate the exception (potentially crashing the explorer.exe-hosted shell extension).","triggerScenarios":"Accessing PathHelpers.FileConverterPath, PathHelpers.DefaultSettingsFilePath or PathHelpers.UserSettingsFilePath-adjacent code when HKCU\\Software\\FileConverter is absent; the FileConverter shell extension DLL is registered but the host app was never installed (or was uninstalled) for the current user; running the extension under a different user account than the one that ran the installer.","commonSituations":"App never installed on the machine; app uninstalled but the shell extension DLL still registered; per-machine install that wrote HKLM\\Software\\FileConverter instead of HKCU; the installer failed to write the registry 'Path' value; running as a different user than the installer user.","solutions":["Run the FileConverter installer for the current user so it creates HKCU\\Software\\FileConverter with the 'Path' value pointing at FileConverter.exe.","If already installed, verify the key exists (reg query HKCU\\Software\\FileConverter) and that its 'Path' value is correct; re-run the installer / repair if missing.","For a per-machine install that wrote HKLM, either install per-user or mirror the key into HKCU.","In extension code, wrap every PathHelpers access in try/catch and degrade gracefully (disable context-menu items) instead of letting the throw escape into explorer.","Manually create the key as a last resort: set HKCU\\Software\\FileConverter\\Path = full path to FileConverter.exe."],"exampleFix":"// before (extension entry point)\nstring exePath = PathHelpers.FileConverterPath; // throws if key absent\n\n// after\nstring exePath;\ntry\n{\n    exePath = PathHelpers.FileConverterPath;\n}\ncatch (Exception ex) when (ex.Message.Contains(\"registry entry\"))\n{\n    // FileConverter not installed for this user; disable shell features.\n    exePath = null;\n}","handlingStrategy":"try-catch","validationCode":"using Microsoft.Win32;\n\n// Probe before relying on PathHelpers\nusing (var key = Registry.CurrentUser.OpenSubKey(@\"Software\\FileConverter\"))\n{\n    if (key == null || string.IsNullOrEmpty(key.GetValue(\"Path\") as string))\n    {\n        // FileConverter is not installed for this user; disable shell features.\n        return;\n    }\n}\n\nstring exePath = PathHelpers.FileConverterPath;","typeGuard":"private static bool IsFileConverterInstalled() =>\n    Registry.CurrentUser.OpenSubKey(@\"Software\\FileConverter\")?.GetValue(\"Path\") as string != null;","tryCatchPattern":"string exePath;\ntry\n{\n    exePath = PathHelpers.FileConverterPath;\n}\ncatch (Exception ex) when (ex.Message.Contains(\"registry entry\"))\n{\n    // HKCU\\Software\\FileConverter missing: degrade gracefully instead of crashing the shell.\n    logger.Warn(ex, \"FileConverter registry key absent; extension disabled.\");\n    exePath = null;\n}","preventionTips":["Run the FileConverter installer for the current user so it writes HKCU\\Software\\FileConverter\\Path.","In the shell extension, wrap every PathHelpers call in try/catch and no-op when the key is absent.","After uninstall/reinstall or a user switch, verify the key exists with reg query HKCU\\Software\\FileConverter.","Mirror a per-machine (HKLM) install into HKCU if the extension reads HKCU only.","Expose an IsFileConverterInstalled() guard at every extension entry point and bail out before touching PathHelpers."],"tags":["csharp","fileconverter","windows-registry","shell-extension","installation","environment","hkcu"],"backgroundTag":null,"analyzedSha":"6c157a411fb70fb7440d2e3b226042781fd55b15","analyzedAt":"2026-08-13T15:04:08.307Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}