BCUninstaller/Bulk-Crap-Uninstaller · error · ArgumentException

Cannot remove the default value

Error message

Cannot remove the default value

What it means

Thrown by RemoveRegistryValue when valueName is null or empty (localized key RegistryTools_RemoveRegistryKey_RemoveDefault). The helper deliberately refuses to delete the unnamed (default) registry value as a safety measure, so an empty name is treated as an attempt to do exactly that.

Source

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

            {
                if (key != null)
                {
                    var subkeyName = Path.GetFileName(fullRegistryPath);
                    // Check if key exists before attempting to remove to avoid an exception
                    if (key.GetSubKeyNames().Contains(subkeyName, StringComparison.OrdinalIgnoreCase))
                        key.DeleteSubKeyTree(subkeyName);
                }
            }
        }

        public static void RemoveRegistryValue(string fullRegistryPath, string valueName)
        {
            if (string.IsNullOrEmpty(fullRegistryPath))
                throw new ArgumentException(Localisation.RegistryTools_RemoveRegistryKey_PathEmptyNull,
                    nameof(fullRegistryPath));

            if (string.IsNullOrEmpty(valueName))
                throw new ArgumentException(Localisation.RegistryTools_RemoveRegistryKey_RemoveDefault,
                    nameof(valueName));

            if (fullRegistryPath.Count(x => x.Equals('\\')) < 2)
                throw new ArgumentException(Localisation.RegistryTools_RemoveRegistryKey_PointsAtRoot,
                    nameof(fullRegistryPath));

            using (var key = OpenRegistryKey(fullRegistryPath, true))
            {
                key?.DeleteValue(valueName);
            }
        }

        private static void RunRegeditCommand(string command)
        {
            foreach (var process in Process.GetProcessesByName("regedit"))
            {
                try { process.Kill(); }
                catch (InvalidOperationException) { }

View on GitHub (pinned to 608321de98)

Solutions

  1. Skip entries with null/empty value names, or handle the default-value case explicitly.
  2. Ensure valueName is a real, named value before calling RemoveRegistryValue.
  3. If deleting the default value is genuinely required, open the key and call DeleteValue(string.Empty) directly with explicit intent.

Example fix

// before
RegistryTools.RemoveRegistryValue(path, entry.Name); // entry.Name empty for default

// after
if (!string.IsNullOrEmpty(entry.Name))
    RegistryTools.RemoveRegistryValue(path, entry.Name);
Defensive patterns

Strategy: validation

Validate before calling

if (string.IsNullOrEmpty(valueName))
    return; // or handle default-value deletion explicitly via RegistryKey.DeleteValue(string.Empty)

Type guard

static bool IsNamedValue(string s) => !string.IsNullOrEmpty(s);

Try / catch

try { RegistryTools.RemoveRegistryValue(path, valueName); }
catch (ArgumentException ex) when (ex.Message.Contains("default"))
{ /* skip the unnamed value */ }

Prevention

When it happens

Trigger: Calling RemoveRegistryValue(path, null), RemoveRegistryValue(path, ""), or with a whitespace-only value name.

Common situations: Iterating value names where one entry is the default; UI letting the user clear the value-name field; code that treats 'default value' and 'remove value' as the same operation.

Related errors


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