From 23e6c523cfe638d53508d6ca8212ca23501049ce Mon Sep 17 00:00:00 2001 From: Andrey Akinshin Date: Tue, 6 Aug 2024 15:38:44 +0200 Subject: [PATCH] Fix InvalidOperationException in DotMemoryDiagnoser If a DotMemoryDiagnoser instance is reused and previous AfterActualRun failed, we shouldn't throw on the second attempt to init the tool --- .../DotMemoryDiagnoser.cs | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/BenchmarkDotNet.Diagnostics.dotMemory/DotMemoryDiagnoser.cs b/src/BenchmarkDotNet.Diagnostics.dotMemory/DotMemoryDiagnoser.cs index 46789b518c..24e62feb31 100644 --- a/src/BenchmarkDotNet.Diagnostics.dotMemory/DotMemoryDiagnoser.cs +++ b/src/BenchmarkDotNet.Diagnostics.dotMemory/DotMemoryDiagnoser.cs @@ -45,10 +45,11 @@ public void Handle(HostSignal signal, DiagnoserActionParameters parameters) switch (signal) { case HostSignal.BeforeAnythingElse: - if (tool is not null) - throw new InvalidOperationException("DotMemory tool is already initialized"); - tool = new DotMemoryTool(logger, nugetUrl, downloadTo: toolsDownloadFolder); - tool.Init(); + if (tool is null) + { + tool = new DotMemoryTool(logger, nugetUrl, downloadTo: toolsDownloadFolder); + tool.Init(); + } break; case HostSignal.BeforeActualRun: if (tool is null)