{"record":{"id":"b078c2f70942ed64","repo":"BCUninstaller/Bulk-Crap-Uninstaller","slug":"path-does-not-point-to-a-valid-reg-file","errorCode":null,"errorMessage":"Path does not point to a valid .reg file","messagePattern":"Path does not point to a valid \\.reg file","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"source/KlocTools/Tools/RegistryTools.cs","lineNumber":96,"sourceCode":"                var valueData = sourceKey.GetValue(valueName);\n                var valueKind = sourceKey.GetValueKind(valueName);\n                destinationKey.SetValue(valueName, valueData!, valueKind);\n            }\n\n            foreach (var sourceSubKeyName in sourceKey.GetSubKeyNames())\n            {\n                using (var destSubKey = destinationKey.CreateSubKey(sourceSubKeyName))\n                using (var sourceSubKey = sourceKey.OpenSubKey(sourceSubKeyName, true))\n                    RecurseCopyKey(sourceSubKey, destSubKey);\n            }\n        }\n\n        public static void AddRegToRegistry(string fullFilename, bool silent)\n        {\n            if (fullFilename == null)\n                throw new ArgumentNullException(nameof(fullFilename));\n            if (!File.Exists(fullFilename) || !fullFilename.EndsWith(\".reg\", StringComparison.CurrentCultureIgnoreCase))\n                throw new ArgumentException(Localisation.RegistryTools_AddRegToRegistry_FileNotExist,\n                    nameof(fullFilename));\n\n            RunRegeditCommand($\"{(silent ? \"/s \" : string.Empty)}\\\"{fullFilename}\\\"\");\n        }\n\n        /// <summary>\n        ///     Export all of the supplied keys to a .reg file using Regedit\n        /// </summary>\n        /// <param name=\"outputFileName\"></param>\n        /// <param name=\"registryPaths\"></param>\n        /// <returns>False if nothing was written, else true</returns>\n        public static bool ExportRegistry(string outputFileName, IEnumerable<string> registryPaths)\n        {\n            var result = new List<string>();\n            var firstPass = true;\n\n            foreach (var regPath in registryPaths)\n            {","sourceCodeStart":78,"sourceCodeEnd":114,"githubUrl":"https://github.com/BCUninstaller/Bulk-Crap-Uninstaller/blob/608321de98e92297377b1eb69029af55c25504a1/source/KlocTools/Tools/RegistryTools.cs#L78-L114","documentation":"Thrown by RegistryTools.AddRegToRegistry(string fullFilename, bool silent). After a null check, if the file does not exist OR its extension is not \".reg\" (case-insensitive, current culture), it throws ArgumentException(Localisation.RegistryTools_AddRegToRegistry_FileNotExist, nameof(fullFilename)) — \"Path does not point to a valid .reg file\". The method then shells out to regedit, so it must reject bad input first.","triggerScenarios":"Passing a path to a missing file, a file with the wrong extension (.txt, .reg.txt), or a typo'd path. Also triggered by relative paths that do not resolve under the current working directory.","commonSituations":"User-selected export file that was moved/deleted, download whose extension was mangled, path read from config that is stale, or non-ASCII path issues with the EndsWith comparison.","solutions":["Resolve to an absolute path and call File.Exists before invoking, surfacing a clear error to the user.","Restrict the open-file dialog filter to *.reg so only valid files can be chosen.","If the file lacks the extension but is genuinely a .reg export, rename/copy it to *.reg first."],"exampleFix":"// before\nRegistryTools.AddRegToRegistry(path, silent: true); // path may be missing/wrong ext\n\n// after\nif (!File.Exists(path) || !path.EndsWith(\".reg\", StringComparison.OrdinalIgnoreCase))\n    throw new FileNotFoundException(\"Select a valid .reg file\", path);\nRegistryTools.AddRegToRegistry(path, silent: true);","handlingStrategy":"validation","validationCode":"fullFilename = Path.GetFullPath(fullFilename);\nif (!File.Exists(fullFilename) || !fullFilename.EndsWith(\".reg\", StringComparison.OrdinalIgnoreCase))\n    throw new FileNotFoundException(\"Select a valid .reg file\", fullFilename);\nRegistryTools.AddRegToRegistry(fullFilename, silent);","typeGuard":"static bool IsValidRegPath(string p)\n    => !string.IsNullOrEmpty(p) && File.Exists(p)\n       && p.EndsWith(\".reg\", StringComparison.OrdinalIgnoreCase);","tryCatchPattern":"try { RegistryTools.AddRegToRegistry(path, silent: true); }\ncatch (ArgumentException ex) when (ex.Message.Contains(\".reg file\"))\n{ /* prompt the user to pick a valid .reg file */ }","preventionTips":["Restrict the open dialog filter to *.reg.","Resolve to an absolute path and check existence before invoking.","Re-validate paths read from config at load time."],"tags":["registry","filesystem","validation","windows","csharp","kloctools"],"backgroundTag":null,"analyzedSha":"608321de98e92297377b1eb69029af55c25504a1","analyzedAt":"2026-08-13T12:17:35.389Z","schemaVersion":2},"datasetVersion":"2026-08-13T14:17:21.547Z"}