BCUninstaller/Bulk-Crap-Uninstaller · error · ArgumentException

Path cannot be empty or null

Error message

Path cannot be empty or null

What it means

Thrown by RemoveRegistryKey when fullRegistryPath is null or empty (localized key RegistryTools_RemoveRegistryKey_PathEmptyNull). The method needs a non-empty path to identify which key to delete and refuses to proceed with nothing to operate on.

Source

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

            return firstSplitter >= fullPath.Length - 1
                ? string.Empty
                : fullPath.Substring(firstSplitter + 1);
        }

        /*/// <exception cref="ArgumentException">Path can't be empty or null</exception>
        public static string GetParentRegistryPath(string fullRegistryPath)
        {
            if (string.IsNullOrEmpty(fullRegistryPath))
                throw new ArgumentException("Path can't be empty or null", "fullRegistryPath");
            fullRegistryPath.TrimEnd('\\');
            var lastIndex = fullRegistryPath.LastIndexOf('\\');
            return fullRegistryPath.Substring(0, lastIndex);
        }*/

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

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

            using (var key = OpenRegistryKey(Path.GetDirectoryName(fullRegistryPath), true))
            {
                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);
                }
            }
        }

View on GitHub (pinned to 608321de98)

Solutions

  1. Guard the caller: skip or report when string.IsNullOrWhiteSpace(fullRegistryPath).
  2. Ensure the path comes from a trusted source that always emits a full hive-rooted value.
  3. Bind the remove action to a non-null selection in the UI layer so the API is never reached with empty input.

Example fix

// before
RegistryTools.RemoveRegistryKey(selectedPath); // selectedPath can be null

// after
if (!string.IsNullOrWhiteSpace(selectedPath))
    RegistryTools.RemoveRegistryKey(selectedPath);
Defensive patterns

Strategy: validation

Validate before calling

if (string.IsNullOrWhiteSpace(fullRegistryPath))
    return; // no-op instead of throwing

Type guard

static bool IsRemovableTarget(string s) =>
    !string.IsNullOrWhiteSpace(s) && s.Count(c => c == '\\') >= 2;

Try / catch

try { RegistryTools.RemoveRegistryKey(path); }
catch (ArgumentException ex) when (ex.Message.Contains("empty"))
{ /* nothing to remove; log and continue */ }

Prevention

When it happens

Trigger: Calling RemoveRegistryKey(null), RemoveRegistryKey(""), or RemoveRegistryKey with a whitespace-only string before any normalization.

Common situations: UI 'remove' button clicked with no selection; list-view SelectedItem cast to null; config deserialization yielding empty path fields; pipelines that pass through unset values.

Related errors


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