{"record":{"id":"95d4d28f5dd505d0","repo":"dotnet/BenchmarkDotNet","slug":"the-process-instance-is-not-set","errorCode":null,"errorMessage":"The process instance is not set.","messagePattern":"The process instance is not set\\.","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"src/BenchmarkDotNet/Diagnosers/DiagnoserActionParameters.cs","lineNumber":18,"sourceCode":"using BenchmarkDotNet.Configs;\nusing BenchmarkDotNet.Running;\nusing System.Diagnostics;\n\nnamespace BenchmarkDotNet.Diagnosers\n{\n    public class DiagnoserActionParameters\n    {\n        public DiagnoserActionParameters(Process? process, BenchmarkCase benchmarkCase, BenchmarkId benchmarkId)\n        {\n            Process = process;\n            BenchmarkCase = benchmarkCase;\n            BenchmarkId = benchmarkId;\n        }\n\n        public Process? Process { get; }\n\n        public int ProcessId => Process?.Id ?? throw new InvalidOperationException(\"The process instance is not set.\");\n\n        public BenchmarkCase BenchmarkCase { get; }\n\n        public BenchmarkId BenchmarkId { get; }\n\n        public ImmutableConfig Config => BenchmarkCase.Config;\n    }\n}","sourceCodeStart":1,"sourceCodeEnd":26,"githubUrl":"https://github.com/dotnet/BenchmarkDotNet/blob/b515068b61ad1c9c9aa938b8ece4af1e7d6d85a3/src/BenchmarkDotNet/Diagnosers/DiagnoserActionParameters.cs#L1-L26","documentation":"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.","triggerScenarios":"A diagnoser constructed DiagnoserActionParameters with a null Process (process not yet started, failed to attach, or not captured) and then code read .ProcessId.","commonSituations":"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.","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."],"exampleFix":"// before\nvar id = parameters.ProcessId; // throws if Process is null\n\n// after\nif (parameters.Process is Process p)\n    var id = p.Id;\nelse\n    return; // or handle the no-process case","handlingStrategy":"validation","validationCode":"if (parameters.Process is not Process p)\n    throw new InvalidOperationException(\"A live process is required to read the process id.\");\nvar id = p.Id;","typeGuard":"static bool HasProcess(DiagnoserActionParameters p) => p.Process is not null;","tryCatchPattern":"try { var id = parameters.ProcessId; }\ncatch (InvalidOperationException ex) when (ex.Message.Contains(\"process instance is not set\"))\n{\n    // skip the diagnoser step that needs the id, or wait for attach\n}","preventionTips":["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."],"tags":["diagnosers","process","nullable","invalidoperation"],"backgroundTag":null,"analyzedSha":"b515068b61ad1c9c9aa938b8ece4af1e7d6d85a3","analyzedAt":"2026-08-13T19:12:24.196Z","schemaVersion":2},"datasetVersion":"2026-08-14T00:17:13.853Z"}