dotnet/BenchmarkDotNet · error · InvalidOperationException
The process instance is not set.
Error message
The process instance is not set.
What it means
DiagnoserActionParameters.ProcessId is a computed getter: it returns Process?.Id and throws InvalidOperationException when the Process field is null. The constructor accepts a nullable Process because some diagnosers can legitimately run without a live process (e.g. dry runs, or diagnosers that attach lazily); only the ProcessId accessor demands one.
Source
Thrown at src/BenchmarkDotNet/Diagnosers/DiagnoserActionParameters.cs:18
using BenchmarkDotNet.Configs;
using BenchmarkDotNet.Running;
using System.Diagnostics;
namespace BenchmarkDotNet.Diagnosers
{
public class DiagnoserActionParameters
{
public DiagnoserActionParameters(Process? process, BenchmarkCase benchmarkCase, BenchmarkId benchmarkId)
{
Process = process;
BenchmarkCase = benchmarkCase;
BenchmarkId = benchmarkId;
}
public Process? Process { get; }
public int ProcessId => Process?.Id ?? throw new InvalidOperationException("The process instance is not set.");
public BenchmarkCase BenchmarkCase { get; }
public BenchmarkId BenchmarkId { get; }
public ImmutableConfig Config => BenchmarkCase.Config;
}
}View on GitHub (pinned to b515068b61)
Solutions
- Null-check params.Process before reading ProcessId: if (params.Process is { } p) { use p.Id }.
- Ensure the process is started/attached before constructing DiagnoserActionParameters, passing a non-null Process.
- For diagnosers that can run without a process, avoid reading ProcessId on that code path.
- Log/warn when Process is null rather than dereferencing ProcessId unconditionally.
Example fix
// before
var id = parameters.ProcessId; // throws if Process is null
// after
if (parameters.Process is Process p)
var id = p.Id;
else
return; // or handle the no-process case Defensive patterns
Strategy: validation
Validate before calling
if (parameters.Process is not Process p)
throw new InvalidOperationException("A live process is required to read the process id.");
var id = p.Id; Type guard
static bool HasProcess(DiagnoserActionParameters p) => p.Process is not null;
Try / catch
try { var id = parameters.ProcessId; }
catch (InvalidOperationException ex) when (ex.Message.Contains("process instance is not set"))
{
// skip the diagnoser step that needs the id, or wait for attach
} Prevention
- Null-check DiagnoserActionParameters.Process before reading ProcessId.
- Ensure the benchmark process is started/attached before constructing the parameters.
- Avoid reading ProcessId on code paths that intentionally run without a process.
When it happens
Trigger: A diagnoser constructed DiagnoserActionParameters with a null Process (process not yet started, failed to attach, or not captured) and then code read .ProcessId.
Common situations: Diagnoser code paths that assume a process exists when the benchmark process failed to launch, in-process diagnoser scenarios, or custom diagnosers that do not guard ProcessId.
Related errors
- There is no default resolver for {characteristic.FullId}
- The current object {this} is frozen. Create a copy to modify
- The current operation allowed for root nodes only, but the v
- There is no default resolver for {characteristic.FullId}
- The argument must be an array
AI-assisted analysis of dotnet/BenchmarkDotNet@b515068b61 (2026-08-13).
Data as JSON: /api/errors/95d4d28f5dd505d0.
Report an issue: GitHub.