{"record":{"id":"ddb6c67a7343b49b","repo":"BCUninstaller/Bulk-Crap-Uninstaller","slug":"process-name-can-t-be-null-or-empty","errorCode":null,"errorMessage":"Process name can't be null or empty","messagePattern":"Process name can't be null or empty","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"source/KlocTools/Tools/ProcessTools.cs","lineNumber":95,"sourceCode":"            {\n                var proc = Process.GetProcessById(pid);\n                proc.Kill();\n            }\n            catch (ArgumentException)\n            {\n                // Process already exited.\n            }\n        }\n\n        /// <exception cref=\"ArgumentException\">processName</exception>\n        /// <exception cref=\"InvalidOperationException\">\n        ///     There are problems accessing the performance counter API's used to get\n        ///     process information. This exception is specific to Windows NT, Windows 2000, and Windows XP.\n        /// </exception>\n        public static bool SafeKillProcess(string processName)\n        {\n            if (string.IsNullOrEmpty(processName))\n                throw new ArgumentException(@\"Process name can't be null or empty\", nameof(processName));\n\n            foreach (var p in Process.GetProcessesByName(processName))\n            {\n                try\n                {\n                    p.Kill();\n                    p.WaitForExit(); // possibly with a timeout\n                    return true;\n                }\n                catch (Win32Exception)\n                {\n                    // process was terminating or can't be terminated - deal with it\n                    return false;\n                }\n                catch (InvalidOperationException)\n                {\n                    // process has already exited - might be able to let this one go\n                    return true;","sourceCodeStart":77,"sourceCodeEnd":113,"githubUrl":"https://github.com/BCUninstaller/Bulk-Crap-Uninstaller/blob/608321de98e92297377b1eb69029af55c25504a1/source/KlocTools/Tools/ProcessTools.cs#L77-L113","documentation":"Thrown by ProcessTools.SafeKillProcess(string processName) when processName is null or empty. The guard precedes Process.GetProcessesByName, which would otherwise match nothing useful (or everything for empty strings depending on platform). It uses ArgumentException(nameof(processName)).","triggerScenarios":"Calling SafeKillProcess(null) or SafeKillProcess(\"\") or SafeKillProcess(\"   \") (note: whitespace-only is NOT caught — only null/empty).","commonSituations":"Reading a process name from config that is missing, a UI text box left blank, or a variable that was never assigned before the kill call.","solutions":["Check string.IsNullOrWhiteSpace(processName) before calling and handle the empty case in the UI/config layer.","Default the variable to a known process name when unset.","Strip a trailing \".exe\" only after confirming the name is non-empty (GetProcessesByName expects the bare name)."],"exampleFix":"// before\nProcessTools.SafeKillProcess(name); // name may be null/empty\n\n// after\nif (!string.IsNullOrWhiteSpace(name))\n    ProcessTools.SafeKillProcess(name.Trim());","handlingStrategy":"validation","validationCode":"if (string.IsNullOrWhiteSpace(processName)) return false;\nreturn ProcessTools.SafeKillProcess(processName.Trim());","typeGuard":"static bool IsValidProcessName(string s) => !string.IsNullOrWhiteSpace(s);","tryCatchPattern":null,"preventionTips":["Validate process names at the UI/config boundary, not at the kill call.","Pass the bare name (no .exe) to GetProcessesByName-based helpers.","Default unset names to a sentinel you skip explicitly."],"tags":["process","validation","csharp","kloctools","windows"],"backgroundTag":null,"analyzedSha":"608321de98e92297377b1eb69029af55c25504a1","analyzedAt":"2026-08-13T12:17:35.389Z","schemaVersion":2},"datasetVersion":"2026-08-13T14:17:21.547Z"}