BCUninstaller/Bulk-Crap-Uninstaller · error · ArgumentException

Path does not point to a valid .reg file

Error message

Path does not point to a valid .reg file

What it means

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.

Source

Thrown at source/KlocTools/Tools/RegistryTools.cs:96

                var valueData = sourceKey.GetValue(valueName);
                var valueKind = sourceKey.GetValueKind(valueName);
                destinationKey.SetValue(valueName, valueData!, valueKind);
            }

            foreach (var sourceSubKeyName in sourceKey.GetSubKeyNames())
            {
                using (var destSubKey = destinationKey.CreateSubKey(sourceSubKeyName))
                using (var sourceSubKey = sourceKey.OpenSubKey(sourceSubKeyName, true))
                    RecurseCopyKey(sourceSubKey, destSubKey);
            }
        }

        public static void AddRegToRegistry(string fullFilename, bool silent)
        {
            if (fullFilename == null)
                throw new ArgumentNullException(nameof(fullFilename));
            if (!File.Exists(fullFilename) || !fullFilename.EndsWith(".reg", StringComparison.CurrentCultureIgnoreCase))
                throw new ArgumentException(Localisation.RegistryTools_AddRegToRegistry_FileNotExist,
                    nameof(fullFilename));

            RunRegeditCommand($"{(silent ? "/s " : string.Empty)}\"{fullFilename}\"");
        }

        /// <summary>
        ///     Export all of the supplied keys to a .reg file using Regedit
        /// </summary>
        /// <param name="outputFileName"></param>
        /// <param name="registryPaths"></param>
        /// <returns>False if nothing was written, else true</returns>
        public static bool ExportRegistry(string outputFileName, IEnumerable<string> registryPaths)
        {
            var result = new List<string>();
            var firstPass = true;

            foreach (var regPath in registryPaths)
            {

View on GitHub (pinned to 608321de98)

Solutions

  1. Resolve to an absolute path and call File.Exists before invoking, surfacing a clear error to the user.
  2. Restrict the open-file dialog filter to *.reg so only valid files can be chosen.
  3. If the file lacks the extension but is genuinely a .reg export, rename/copy it to *.reg first.

Example fix

// before
RegistryTools.AddRegToRegistry(path, silent: true); // path may be missing/wrong ext

// after
if (!File.Exists(path) || !path.EndsWith(".reg", StringComparison.OrdinalIgnoreCase))
    throw new FileNotFoundException("Select a valid .reg file", path);
RegistryTools.AddRegToRegistry(path, silent: true);
Defensive patterns

Strategy: validation

Validate before calling

fullFilename = Path.GetFullPath(fullFilename);
if (!File.Exists(fullFilename) || !fullFilename.EndsWith(".reg", StringComparison.OrdinalIgnoreCase))
    throw new FileNotFoundException("Select a valid .reg file", fullFilename);
RegistryTools.AddRegToRegistry(fullFilename, silent);

Type guard

static bool IsValidRegPath(string p)
    => !string.IsNullOrEmpty(p) && File.Exists(p)
       && p.EndsWith(".reg", StringComparison.OrdinalIgnoreCase);

Try / catch

try { RegistryTools.AddRegToRegistry(path, silent: true); }
catch (ArgumentException ex) when (ex.Message.Contains(".reg file"))
{ /* prompt the user to pick a valid .reg file */ }

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Related errors


AI-assisted analysis of BCUninstaller/Bulk-Crap-Uninstaller@608321de98 (2026-08-13). Data as JSON: /api/errors/b078c2f70942ed64. Report an issue: GitHub.