0

I'm trying to debug unit tests in visual Studio 2015 but when I try to debug wether a test method or a test class, the output contains the following error :

System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.ArgumentException: Process with an Id of -1 is not running.

All my tests are based on nunit.

When I run the test without debugging, everything works fine. I use Debug / x64 platform to build my solution and the default test processor architecture is x64. I have tried to change to Debug / AnyCPU and targetting wether x64 or x86 but it does not change anything.

At the moment, my solution to debug the test is to run the test outside VS and attach to the test runner in Visual Studio but that's not really convenient.

Any clues welcome.

Thanks in advance

Regards

Bellow is the full trace shown in the output window :

Enqueue operation 'RunSelectedWithDebugOperation', hashcode:12843996 
Operation left in the the queue: 1
    'RunSelectedWithDebugOperation', hashcode:12843996


Processing Queue .....
Operation Dequeue : 'RunSelectedWithDebugOperation'
VirtualReadOnlyTestDataStore.OperationStateChanged State=OperationSetStarted, operationInProgress=False
TestDiscoveryStats.OperationStateChanged State=OperationSetStarted, InProgress=False
VirtualReadOnlyTestDataStore.OperationStateChanged State=ChangeDetectionStarting, operationInProgress=True
TestDiscoveryStats.OperationStateChanged State=ChangeDetectionStarting, InProgress=False
We programmatically start the build in TestWindowHost.UpdateContainer... 
After we await the build that programmatically started in TestWindowHost.UpdateContainer... 
TestContainer update (build) complete : 638 ms
Containers from 'Microsoft.VisualStudio.TestWindow.VsAdapters.VsProjectOutputContainerDiscoverer' :
    C:\dev\workspaces\PFM\89c3_app_meniga_cs\Meniga.BPCE.Common.CustomExtensions.Aggregation.Tests\bin\x64\Debug\Meniga.BPCE.Common.CustomExtensions.Aggregation.Tests.dll:executor://vsprojectoutputcontainerdiscoverer/v1
    C:\dev\workspaces\PFM\89c3_app_meniga_cs\Meniga.BPCE.Common.CustomExtensions.Aggregation\bin\x64\Debug\Meniga.BPCE.Common.CustomExtensions.Aggregation.dll:executor://vsprojectoutputcontainerdiscoverer/v1
    C:\dev\workspaces\PFM\89c3_app_meniga_cs\Meniga.BPCE.Common.CustomExtensions.Cache.Tests\bin\x64\Debug\Meniga.BPCE.Common.CustomExtensions.Cache.Tests.dll:executor://vsprojectoutputcontainerdiscoverer/v1
    C:\dev\workspaces\PFM\89c3_app_meniga_cs\Meniga.BPCE.Common.CustomExtensions.Cache\bin\x64\Debug\Meniga.BPCE.Common.CustomExtensions.Cache.dll:executor://vsprojectoutputcontainerdiscoverer/v1
    C:\dev\workspaces\PFM\89c3_app_meniga_cs\Meniga.BPCE.Common.CustomExtensions.DataInserters.Tests\bin\x64\Debug\Meniga.BPCE.Common.CustomExtensions.DataInserters.Tests.dll:executor://vsprojectoutputcontainerdiscoverer/v1
    C:\dev\workspaces\PFM\89c3_app_meniga_cs\Meniga.BPCE.Common.CustomExtensions.DataInserters\bin\x64\Debug\Meniga.BPCE.Common.CustomExtensions.DataInserters.dll:executor://vsprojectoutputcontainerdiscoverer/v1
    C:\dev\workspaces\PFM\89c3_app_meniga_cs\Meniga.BPCE.Common.CustomExtensions.DataModels\bin\x64\Debug\Meniga.BPCE.Common.CustomExtensions.DataModels.dll:executor://vsprojectoutputcontainerdiscoverer/v1
    C:\dev\workspaces\PFM\89c3_app_meniga_cs\Meniga.BPCE.Common.CustomExtensions.MQ.Tests\bin\x64\Debug\Meniga.BPCE.Common.CustomExtensions.MQ.Tests.dll:executor://vsprojectoutputcontainerdiscoverer/v1
    C:\dev\workspaces\PFM\89c3_app_meniga_cs\Meniga.BPCE.Common.CustomExtensions.MQ\bin\x64\Debug\Meniga.BPCE.Common.CustomExtensions.MQ.dll:executor://vsprojectoutputcontainerdiscoverer/v1
    C:\dev\workspaces\PFM\89c3_app_meniga_cs\Meniga.BPCE.Common.CustomExtensions.ScheduledPayments.Tests\bin\x64\Debug\Meniga.BPCE.Common.CustomExtensions.ScheduledPayments.Tests.dll:executor://vsprojectoutputcontainerdiscoverer/v1
    C:\dev\workspaces\PFM\89c3_app_meniga_cs\Meniga.BPCE.Common.CustomExtensions.ScheduledPayments\bin\x64\Debug\Meniga.BPCE.Common.CustomExtensions.ScheduledPayments.dll:executor://vsprojectoutputcontainerdiscoverer/v1
    C:\dev\workspaces\PFM\89c3_app_meniga_cs\Meniga.BPCE.Common.CustomExtensions.ServiceExtensions.Tests\bin\x64\Debug\Meniga.BPCE.Common.CustomExtensions.ServiceExtensions.Tests.dll:executor://vsprojectoutputcontainerdiscoverer/v1
    C:\dev\workspaces\PFM\89c3_app_meniga_cs\Meniga.BPCE.Common.CustomExtensions.ServiceExtensions\bin\x64\Debug\Meniga.BPCE.Common.CustomExtensions.ServiceExtensions.dll:executor://vsprojectoutputcontainerdiscoverer/v1
    C:\dev\workspaces\PFM\89c3_app_meniga_cs\Meniga.BPCE.Common.CustomExtensions.TextParsers.Tests\bin\x64\Debug\Meniga.BPCE.Common.CustomExtensions.TextParsers.Tests.dll:executor://vsprojectoutputcontainerdiscoverer/v1
    C:\dev\workspaces\PFM\89c3_app_meniga_cs\Meniga.BPCE.Common.CustomExtensions.TextParsers\bin\x64\Debug\Meniga.BPCE.Common.CustomExtensions.TextParsers.dll:executor://vsprojectoutputcontainerdiscoverer/v1
    C:\dev\workspaces\PFM\89c3_app_meniga_cs\Meniga.BPCE.Common.CustomExtensions.UserEvents.test\bin\x64\Debug\Meniga.BPCE.Common.CustomExtensions.UserEvents.Tests.dll:executor://vsprojectoutputcontainerdiscoverer/v1
    C:\dev\workspaces\PFM\89c3_app_meniga_cs\Meniga.BPCE.Common.CustomExtensions.UserEvents\bin\x64\Debug\Meniga.BPCE.Common.CustomExtensions.UserEvents.dll:executor://vsprojectoutputcontainerdiscoverer/v1
    C:\dev\workspaces\PFM\89c3_app_meniga_cs\Meniga.CustomExtension.BpceSpecific.Tests\bin\x64\Debug\Meniga.CustomExtension.BpceSpecific.Tests.dll:executor://vsprojectoutputcontainerdiscoverer/v1
    C:\dev\workspaces\PFM\89c3_app_meniga_cs\Meniga.CustomExtension.BpceSpecific\bin\x64\Debug\Meniga.CustomExtension.BpceSpecific.dll:executor://vsprojectoutputcontainerdiscoverer/v1
No containers found from 'Microsoft.VisualStudio.Web.ProjectSystem.UnitTest.KUnitTestContainerDiscoverer' :
No containers found from 'Microsoft.VisualStudio.MSTest.TestWindow.OrderedTestContainerDiscoverer' :
No containers found from 'Microsoft.VisualStudio.MSTest.TestWindow.GenericTestContainerDiscoverer' :
No containers found from 'Microsoft.VisualStudio.MSTest.TestWindow.WebTestContainerDiscoverer' :
DiscoveryOperation<RunSelectedWithDebugOperation> FinishedChangedCotainers, changed container count is 0
VirtualReadOnlyTestDataStore.OperationStateChanged State=ChangeDetectionFinished, operationInProgress=False
TestDiscoveryStats.OperationStateChanged State=ChangeDetectionFinished, InProgress=False
VirtualReadOnlyTestDataStore.OperationStateChanged State=TestExecutionStarting, operationInProgress=False
TestDiscoveryStats.OperationStateChanged State=TestExecutionStarting, InProgress=False
------ Run test started ------
RunSettings Content:
<RunSettings>
  <RunConfiguration>
    <ResultsDirectory>C:\dev\workspaces\PFM\89c3_app_meniga_cs\TestResults</ResultsDirectory>
    <SolutionDirectory>C:\dev\workspaces\PFM\89c3_app_meniga_cs\</SolutionDirectory>
    <TargetPlatform>X64</TargetPlatform>
    <TargetFrameworkVersion>Framework45</TargetFrameworkVersion>
  </RunConfiguration>
</RunSettings>
VirtualReadOnlyTestDataStore.OperationStateChanged State=TestExecutionStarted, operationInProgress=False
TestDiscoveryStats.OperationStateChanged State=TestExecutionStarted, InProgress=False
**  Launching debugger  **
.     Launched process      : C:\PROGRAM FILES (X86)\MICROSOFT VISUAL STUDIO 14.0\COMMON7\IDE\COMMONEXTENSIONS\MICROSOFT\TESTWINDOW\vstest.executionengine.exe
.     Arguments             : /parentProcessId 28948 
.     Current directory     : C:\Program Files (x86)\Microsoft Visual Studio 14.0\Common7\IDE
.     Environment variables : 
.     Engine guid           : 92ef0900-2251-11d2-b72e-0000f87572ef
.     Other options         : 
.     AppPackageLaunchInfo  : 
VirtualReadOnlyTestDataStore.OperationStateChanged State=OperationSetFinished, operationInProgress=False
TestDiscoveryStats.OperationStateChanged State=OperationSetFinished, InProgress=False
***    Run finished using 'InMemoryUnitTestWriter' ***
System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.ArgumentException: Process with an Id of -1 is not running.
   at System.Diagnostics.Process.GetProcessById(Int32 processId, String machineName)
   at System.Diagnostics.Process.GetProcessById(Int32 processId)
   at Microsoft.VisualStudio.TestPlatform.Client.TestExecutorServiceClient.Initialize_NoLock(Architecture targetPlatform, FrameworkVersion targetFramework)
   at Microsoft.VisualStudio.TestPlatform.Client.TestExecutorServiceClient.EnsureInitialized(IDictionary`2 environmentVariables, TestExecutionContext context)
   at Microsoft.VisualStudio.TestPlatform.Client.TestExecutorServiceClient.<>c__DisplayClass17_0.<StartTestRun>b__0()
   at Microsoft.VisualStudio.TestPlatform.Client.TestExecutorServiceClient.InvokeTestExecutorServiceAction(Action action)
   at Microsoft.VisualStudio.TestPlatform.Client.TestExecutorServiceClient.StartTestRun(IEnumerable`1 tests, TestExecutionContext executionContext, String runSettings, IDictionary`2 environmentVariables, String dataCollectionServiceUri, ITestCaseLog testCaseLog, ITestRunLog testRunLog, IFrameworkHandleInternal frameworkHandle)
   at Microsoft.VisualStudio.TestPlatform.Client.Rocksteady.RocksteadyExecutionManager.StartTestRun(TestRunCriteria testRunCriteria, Boolean inIsolation, DataCollectionParameters dataCollectionParameters, ITestRunEventsHandler runEventsHandler)
   at Microsoft.VisualStudio.TestPlatform.Client.TestRunRequest.ExecuteAsync()
   at Microsoft.VisualStudio.TestWindow.Controller.TestRunRequest.OnStart(IRequest request)
   at Microsoft.VisualStudio.TestWindow.Controller.Request.<>c__DisplayClass100_0.<<RunRequest>b__0>d.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Microsoft.VisualStudio.TestWindow.Data.UnitTestStorage.<ExecuteWhileOpen>d__32.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Microsoft.VisualStudio.TestWindow.Controller.Request.<RunRequest>d__100.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Microsoft.VisualStudio.TestWindow.Controller.Request.<RunRequests>d__99.MoveNext()
   --- End of inner exception stack trace ---
   at Microsoft.VisualStudio.TestWindow.Controller.Request.<ProcessRequest>d__98.MoveNext()
========== Run test finished: 0 run (0:00:00,8452663) ==========
VirtualReadOnlyTestDataStore.OperationStateChanged State=TestExecutionFinished, operationInProgress=False
TestDiscoveryStats.OperationStateChanged State=TestExecutionFinished, InProgress=False
Dominique
  • 87
  • 2
  • 7
  • That is a general exception error prompt. And the info is not enough, Did you try to set a breakpoint to locate where the issue is? Also, you should use `try catch` with `TargetInvocationException` to get the original exception to fix your issue. Check [this link](https://stackoverflow.com/questions/32741529/exception-has-been-thrown-by-the-target-of-an-invocation-methodbase-invoke-meth). Also, you could share a small reproducible sample with us to troubleshoot the issue. – Mr Qian Feb 04 '21 at 07:11
  • Hi Perry. As mentioned I cannot debug and so i cannot add any breakpoints. The Debugger is not launched and I cannot do anything. My only solution is to run the test via nunit3-Console.Exe with --pause argument and debug the process in the IDE. – Dominique Feb 04 '21 at 14:15
  • Did you use Attach To Process on VS2015? You have an exception error on your code. And it only appears under debug process. So you cannot find it without debug. And you have to get the origin code of the project. And make any `try-catch` or breakpoint. External methods will not help. You should get the code or share a small sample with us to troubleshoot the issue. – Mr Qian Feb 08 '21 at 03:21
  • Hi. When i run the tests in the IDE, everything works fine. When I try to debug, I get the error message saying that no process with id -1 was running. Nevertheless, running tests via nunit3-console and attaching to the runner so as to debug it works perfectly. But, you must admit that this is not the most convenient way to debug nunit tests.A full integration in the IDE is the awaited behaviour. There is no error thrown by my code, the error above is launched by the test runner in the IDE. – Dominique Mar 16 '21 at 16:18

0 Answers0