BCUninstaller/Bulk-Crap-Uninstaller · error · ArgumentException
Path root is invalid or missing
Error message
Path root is invalid or missing
What it means
Thrown by GetRootHive when the parsed root segment of a registry path does not match any of the supported hive aliases (HKLM, HKCR, HKCU, HKU/HKUS, HKCC, or their HKEY_* long forms). The library refuses to guess a hive, so any unrecognized leading token is treated as a malformed path. It is an ArgumentException, raised after GetKeyRoot has already normalized the leading segment to upper-case.
Source
Thrown at source/KlocTools/Tools/RegistryTools.cs:249
case HklmShortRootName:
rootKey = Registry.LocalMachine;
break;
case HkcrShortRootName:
rootKey = Registry.ClassesRoot;
break;
case HkcuShortRootName:
rootKey = Registry.CurrentUser;
break;
case HkuShortRootName:
case HkuShortRootName2:
rootKey = Registry.Users;
break;
case HkccShortRootName:
rootKey = Registry.CurrentConfig;
break;
default:
throw new ArgumentException("Path root is invalid or missing");
}
return rootKey;
}
/// <summary>
/// Return registry key at supplied path. If the key or its parents don't exist, create them before returning.
/// The returned RegistryKey is writable.
/// </summary>
/// <param name="fullPath">Path of the key to open or create. Not case-sensitive.</param>
public static RegistryKey CreateSubKeyRecursively(string fullPath)
{
if (fullPath == null)
throw new ArgumentNullException(nameof(fullPath));
if (fullPath.Length < 4)
throw new ArgumentException("Path is too short/invalid");
View on GitHub (pinned to 608321de98)
Solutions
- Spell the root as one of: HKLM, HKCR, HKCU, HKU, HKUS, HKCC, or HKEY_LOCAL_MACHINE, HKEY_CLASSES_ROOT, HKEY_CURRENT_USER, HKEY_USERS, HKEY_CURRENT_CONFIG.
- Ensure the root is separated from the rest by a single backslash and that nothing precedes it (no leading whitespace, no drive-style prefixes).
- If you need an unsupported hive (e.g. HKEY_PERFORMANCE_DATA), open it directly via Microsoft.Win32.Registry instead of routing through this helper.
- Log fullPath.ToUpperInvariant() at the call site to see exactly which token the switch is rejecting.
Example fix
// before
var k = RegistryTools.OpenRegistryKey("HKEY_LOCAL_MASHINE\\Software\\Foo", true);
// after
var k = RegistryTools.OpenRegistryKey("HKEY_LOCAL_MACHINE\\Software\\Foo", true);
// or short form
var k = RegistryTools.OpenRegistryKey("HKLM\\Software\\Foo", true); Defensive patterns
Strategy: validation
Validate before calling
private static readonly HashSet<string> ValidRoots = new(StringComparer.OrdinalIgnoreCase)
{
"HKLM","HKCR","HKCU","HKU","HKUS","HKCC",
"HKEY_LOCAL_MACHINE","HKEY_CLASSES_ROOT","HKEY_CURRENT_USER","HKEY_USERS","HKEY_CURRENT_CONFIG"
};
private static bool IsRootValid(string fullPath)
{
if (string.IsNullOrWhiteSpace(fullPath)) return false;
var seg = fullPath.Split('\\', '/')[0];
return ValidRoots.Contains(seg);
} Type guard
static bool IsLikelyRegistryPath(string s) =>
!string.IsNullOrWhiteSpace(s)
&& s.Length >= 4
&& (s.StartsWith("HK", StringComparison.OrdinalIgnoreCase)
|| s.StartsWith("HKEY_", StringComparison.OrdinalIgnoreCase)); Try / catch
try { var k = RegistryTools.OpenRegistryKey(path, writable); }
catch (ArgumentException ex) when (ex.Message.Contains("Path root is invalid"))
{ /* log path.ToUpperInvariant() and surface to user */ } Prevention
- Keep a single shared constant for the accepted hive aliases and build all paths from it.
- Reject paths at the UI boundary before they reach the registry layer.
- Add a unit test that round-trips each supported alias through OpenRegistryKey.
When it happens
Trigger: Calling OpenRegistryKey / CreateSubKeyRecursively / GetRootHive with a path whose first segment is misspelled (e.g. 'HKEY_LOCAL_MASHINE', 'HKLMX'), uses an unsupported hive (HKEY_CURRENT_USER_LOCAL_SETTINGS, HKEY_PERFORMANCE_DATA, HKEY_DYN_DATA), or starts with a relative/empty token before the first backslash.
Common situations: Copy-pasting a registry path from documentation that uses a non-canonical hive name; building paths via string concatenation where the root constant is wrong; paths imported from a .reg file using hive variants the switch does not enumerate; locale-specific typos.
Related errors
- Path cannot be empty or null
- Path cannot point to a root key
- Cannot remove the default value
- Path does not point to a valid .reg file
- Path is too short/invalid
AI-assisted analysis of BCUninstaller/Bulk-Crap-Uninstaller@608321de98 (2026-08-13).
Data as JSON: /api/errors/0a022c116045944a.
Report an issue: GitHub.