BCUninstaller/Bulk-Crap-Uninstaller · error · ArgumentException

Process name can't be null or empty

Error message

Process name can't be null or empty

What it means

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)).

Source

Thrown at source/KlocTools/Tools/ProcessTools.cs:95

            {
                var proc = Process.GetProcessById(pid);
                proc.Kill();
            }
            catch (ArgumentException)
            {
                // Process already exited.
            }
        }

        /// <exception cref="ArgumentException">processName</exception>
        /// <exception cref="InvalidOperationException">
        ///     There are problems accessing the performance counter API's used to get
        ///     process information. This exception is specific to Windows NT, Windows 2000, and Windows XP.
        /// </exception>
        public static bool SafeKillProcess(string processName)
        {
            if (string.IsNullOrEmpty(processName))
                throw new ArgumentException(@"Process name can't be null or empty", nameof(processName));

            foreach (var p in Process.GetProcessesByName(processName))
            {
                try
                {
                    p.Kill();
                    p.WaitForExit(); // possibly with a timeout
                    return true;
                }
                catch (Win32Exception)
                {
                    // process was terminating or can't be terminated - deal with it
                    return false;
                }
                catch (InvalidOperationException)
                {
                    // process has already exited - might be able to let this one go
                    return true;

View on GitHub (pinned to 608321de98)

Solutions

  1. Check string.IsNullOrWhiteSpace(processName) before calling and handle the empty case in the UI/config layer.
  2. Default the variable to a known process name when unset.
  3. Strip a trailing ".exe" only after confirming the name is non-empty (GetProcessesByName expects the bare name).

Example fix

// before
ProcessTools.SafeKillProcess(name); // name may be null/empty

// after
if (!string.IsNullOrWhiteSpace(name))
    ProcessTools.SafeKillProcess(name.Trim());
Defensive patterns

Strategy: validation

Validate before calling

if (string.IsNullOrWhiteSpace(processName)) return false;
return ProcessTools.SafeKillProcess(processName.Trim());

Type guard

static bool IsValidProcessName(string s) => !string.IsNullOrWhiteSpace(s);

Prevention

When it happens

Trigger: Calling SafeKillProcess(null) or SafeKillProcess("") or SafeKillProcess(" ") (note: whitespace-only is NOT caught — only null/empty).

Common situations: 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.

Related errors


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