ElectronNET/Electron.NET · error · ArgumentException
Unable to find process with ID
Error message
Unable to find process with ID {this.pid} What it means
ElectronProcessPassive.StartCore attaches to an already-running Electron process by PID using Process.GetProcessById. .NET's GetProcessById throws ArgumentException when no process with that ID exists; the subsequent null check with this custom message is the library's guard for a missing process.
Solutions
- Verify the target process with the given PID is actually running before starting (Process.GetProcesses / ps)
- Re-launch the Electron host and use its fresh PID
- Check for PID namespace issues when running in containers/WSL
- Confirm the PID is not from a previous, terminated run
Example fix
// before
var proc = Process.GetProcessById(pid); // ArgumentException if gone
// after
if (!Process.GetProcesses().Any(p => p.Id == pid))
throw new InvalidOperationException($"Process {pid} is not running");
var proc = Process.GetProcessById(pid); Defensive patterns
Strategy: validation
Validate before calling
if (!Process.GetProcesses().Any(p => p.Id == pid))
throw new InvalidOperationException($"Electron host process {pid} is not running"); Type guard
bool ProcessExists(int pid) => Process.GetProcesses().Any(p => p.Id == pid);
Try / catch
try
{
await electronProcess.StartAsync();
}
catch (ArgumentException ex)
{
logger.LogWarning(ex, "Host process {Pid} no longer exists — relaunching", pid);
await relaunchHostAsync();
} Prevention
- Use the PID immediately after obtaining it; don't cache across restarts
- Handle host crash events and re-launch rather than reusing stale PIDs
- Beware container/WSL PID isolation when attaching across boundaries
When it happens
Trigger: Starting the passive Electron process lifecycle with a PID that has already exited, a PID from a different OS namespace (e.g. container/host mismatch), or a stale/incorrect PID value.
Common situations: Attaching to an Electron host that crashed or was closed before the .NET side started; passing a PID captured long before use; WSL/container PID isolation hiding the host process.
Understand the failure class
Background: "Not found" and "does not exist" errors: why "Task not found", "No such folder", and "Can't find" fire when a lookup comes back empty — this error's family across 14 libraries.
Related errors
AI-assisted analysis of ElectronNET/Electron.NET@87cc6f98b6 (2026-09-14).
Data as JSON: /api/errors/25523b2264b8af3d.
Report an issue: GitHub.
Appendix: source
Thrown at src/ElectronNET.API/Runtime/Services/ElectronProcess/ElectronProcessPassive.cs:31
internal class ElectronProcessPassive : ElectronProcessBase
{
private readonly int pid;
private Process process;
/// <summary>Initializes a new instance of the <see cref="ElectronProcessPassive"/> class.</summary>
/// <param name="pid"></param>
public ElectronProcessPassive(int pid)
{
this.pid = pid;
}
protected override Task StartCore()
{
this.process = Process.GetProcessById(this.pid);
if (this.process == null)
{
throw new ArgumentException($"Unable to find process with ID {this.pid}");
}
this.process.Exited += this.Process_Exited1;
Task.Run(() => this.TransitionState(LifetimeState.Ready));
return Task.CompletedTask;
}
private void Process_Exited1(object sender, EventArgs e)
{
this.TransitionState(LifetimeState.Stopped);
}
protected override Task StopCore()
{
// Not sure about this:
////this.process.Kill(true);View on GitHub (pinned to 87cc6f98b6)