{"record":{"id":"d835397711abdd5a","repo":"BCUninstaller/Bulk-Crap-Uninstaller","slug":"path-cannot-be-empty-or-null","errorCode":null,"errorMessage":"Path cannot be empty or null","messagePattern":"Path cannot be empty or null","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"source/KlocTools/Tools/RegistryTools.cs","lineNumber":348,"sourceCode":"            return firstSplitter >= fullPath.Length - 1\n                ? string.Empty\n                : fullPath.Substring(firstSplitter + 1);\n        }\n\n        /*/// <exception cref=\"ArgumentException\">Path can't be empty or null</exception>\n        public static string GetParentRegistryPath(string fullRegistryPath)\n        {\n            if (string.IsNullOrEmpty(fullRegistryPath))\n                throw new ArgumentException(\"Path can't be empty or null\", \"fullRegistryPath\");\n            fullRegistryPath.TrimEnd('\\\\');\n            var lastIndex = fullRegistryPath.LastIndexOf('\\\\');\n            return fullRegistryPath.Substring(0, lastIndex);\n        }*/\n\n        public static void RemoveRegistryKey(string fullRegistryPath)\n        {\n            if (string.IsNullOrEmpty(fullRegistryPath))\n                throw new ArgumentException(Localisation.RegistryTools_RemoveRegistryKey_PathEmptyNull,\n                    nameof(fullRegistryPath));\n\n            if (fullRegistryPath.Count(x => x.Equals('\\\\')) < 2)\n                throw new ArgumentException(Localisation.RegistryTools_RemoveRegistryKey_PointsAtRoot,\n                    nameof(fullRegistryPath));\n\n            using (var key = OpenRegistryKey(Path.GetDirectoryName(fullRegistryPath), true))\n            {\n                if (key != null)\n                {\n                    var subkeyName = Path.GetFileName(fullRegistryPath);\n                    // Check if key exists before attempting to remove to avoid an exception\n                    if (key.GetSubKeyNames().Contains(subkeyName, StringComparison.OrdinalIgnoreCase))\n                        key.DeleteSubKeyTree(subkeyName);\n                }\n            }\n        }\n","sourceCodeStart":330,"sourceCodeEnd":366,"githubUrl":"https://github.com/BCUninstaller/Bulk-Crap-Uninstaller/blob/608321de98e92297377b1eb69029af55c25504a1/source/KlocTools/Tools/RegistryTools.cs#L330-L366","documentation":"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.","triggerScenarios":"Calling RemoveRegistryKey(null), RemoveRegistryKey(\"\"), or RemoveRegistryKey with a whitespace-only string before any normalization.","commonSituations":"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.","solutions":["Guard the caller: skip or report when string.IsNullOrWhiteSpace(fullRegistryPath).","Ensure the path comes from a trusted source that always emits a full hive-rooted value.","Bind the remove action to a non-null selection in the UI layer so the API is never reached with empty input."],"exampleFix":"// before\nRegistryTools.RemoveRegistryKey(selectedPath); // selectedPath can be null\n\n// after\nif (!string.IsNullOrWhiteSpace(selectedPath))\n    RegistryTools.RemoveRegistryKey(selectedPath);","handlingStrategy":"validation","validationCode":"if (string.IsNullOrWhiteSpace(fullRegistryPath))\n    return; // no-op instead of throwing","typeGuard":"static bool IsRemovableTarget(string s) =>\n    !string.IsNullOrWhiteSpace(s) && s.Count(c => c == '\\\\') >= 2;","tryCatchPattern":"try { RegistryTools.RemoveRegistryKey(path); }\ncatch (ArgumentException ex) when (ex.Message.Contains(\"empty\"))\n{ /* nothing to remove; log and continue */ }","preventionTips":["Bind destructive UI actions to a non-null, non-empty selection.","Filter empty entries from batch removal lists.","Surf a confirmation dialog before any registry deletion."],"tags":["registry","argument-validation","windows","csharp"],"backgroundTag":null,"analyzedSha":"608321de98e92297377b1eb69029af55c25504a1","analyzedAt":"2026-08-13T12:17:35.389Z","schemaVersion":2},"datasetVersion":"2026-08-13T14:17:21.547Z"}