vscode-csharp icon indicating copy to clipboard operation
vscode-csharp copied to clipboard

Unit Test Debugging with Syntax Error Requires VS Code Restart

Open xcellsoft opened this issue 8 years ago • 10 comments

Environment data

dotnet --info output:

.NET Core SDK (reflecting any global.json): Version: 2.1.301 Commit: 59524873d6

Runtime Environment: OS Name: Windows OS Version: 10.0.17134 OS Platform: Windows RID: win10-x64 Base Path: C:\Program Files\dotnet\sdk\2.1.301\

Host (useful for support): Version: 2.1.1 Commit: 6985b9f684

.NET Core SDKs installed: 2.1.3 [C:\Program Files\dotnet\sdk] 2.1.4 [C:\Program Files\dotnet\sdk] 2.1.101 [C:\Program Files\dotnet\sdk] 2.1.103 [C:\Program Files\dotnet\sdk] 2.1.200 [C:\Program Files\dotnet\sdk] 2.1.201 [C:\Program Files\dotnet\sdk] 2.1.300 [C:\Program Files\dotnet\sdk] 2.1.301 [C:\Program Files\dotnet\sdk]

.NET Core runtimes installed: Microsoft.AspNetCore.All 2.1.0 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All] Microsoft.AspNetCore.All 2.1.1 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All] Microsoft.AspNetCore.App 2.1.0 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 2.1.1 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.NETCore.App 2.0.4 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 2.0.5 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 2.0.6 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 2.0.7 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 2.1.0 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 2.1.1 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]

To install additional .NET Core runtimes or SDKs: https://aka.ms/dotnet-download

VS Code version: 1.24.1 C# Extension version: . vscode\extensions\ms-vscode.csharp-1.15.2.omnisharp\1.30.1\OmniSharp.exe

Steps to reproduce

Create a fresh xunit application using dotnet new xunit , then open the unit test and create a syntax error (this example missing semicolon after assert.true) and click debug:

    public class UnitTest1
    {
        [Fact]
        public void Test1()
        {
            Assert.True(true)
        }
    }

Expected behavior

Syntax error returned, fix error and debug again.

Actual behavior

Syntax error is returned but clicking debug shows two debuggers running and then an error that the debugger is already started. Clicking debug again shows 3 debuggers running and same error, then so on so forth.

.NET Test Log Output

Debugging method 'test.UnitTest1.Test1'...

Microsoft (R) Build Engine version 15.7.179.6572 for .NET Core
Microsoft (R) Build Engine version 15.7.179.6572 for .NET Core
Copyright (C) Microsoft Corporation. All rights reserved.
Copyright (C) Microsoft Corporation. All rights reserved.


  test -> c:\Temp\test\bin\Debug\netcoreapp2.1\test.dll
  test -> c:\Temp\test\bin\Debug\netcoreapp2.1\test.dll


Build succeeded.
Build succeeded.
    0 Warning(s)
    0 Warning(s)
    0 Error(s)
    0 Error(s)


Time Elapsed 00:00:00.67
Time Elapsed 00:00:00.67

Error Message: Failed to start debugger: "System.InvalidOperationException: Debug session already started.\r\n at OmniSharp.DotNetTest.DebugSessionManager.VerifySession(Boolean isStarted)\r\n at OmniSharp.DotNetTest.DebugSessionManager.StartSession(TestManager testManager)\r\n at OmniSharp.DotNetTest.Services.DebugTestService.Handle(DebugTestGetStartInfoRequest request)\r\n at OmniSharp.Endpoint.EndpointHandler2.d__18.MoveNext()\r\n--- End of stack trace from previous location where exception was thrown ---\r\n at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()\r\n at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n at OmniSharp.Endpoint.EndpointHandler2.<Process>d__16.MoveNext()\r\n--- End of stack trace from previous location where exception was thrown ---\r\n at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()\r\n at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n at OmniSharp.Stdio.Host.<HandleRequest>d__15.MoveNext()"

xcellsoft avatar Jun 30 '18 18:06 xcellsoft

@xcellsoft The double , triple times diagnostics is coming because we are not disposing the event listeners properly in the extension, and the problem with the debugger already started is coming because the exceptions are not being handled properly. I am working on it and a PR will be out soon. Thank you for taking time to file the issue.

akshita31 avatar Jul 03 '18 01:07 akshita31

This will save allot of time, can’t wait. Thanks

xcellsoft avatar Jul 03 '18 12:07 xcellsoft

What is the appropriate way to get this fix?

I see that setting "omnisharp.path": "latest" pulls down recent builds, looks like today it's 1.31.2-beta.98, how does this correlate with commits to master and/or what is the best way to get this patch to test it out?

xcellsoft avatar Jul 04 '18 17:07 xcellsoft

@xcellsoft Just setting "omnisharp.path": "latest" and restarting the omnisharp server will make the debugger work for you. However you will see duplicate logs if the debugger failed initially. The change for that has been merged to master in omnisharp-vscode. We are in talks of doing a beta release. Until then you can follow the steps here to create a vsix and then install it.

akshita31 avatar Jul 04 '18 17:07 akshita31

"Just setting "omnisharp.path": "latest" and restarting the omnisharp server will make the debugger work for you. However you will see duplicate logs if the debugger failed initially"

Didn't work for me.

mubarik avatar Nov 12 '18 17:11 mubarik

@akshita31

mubarik avatar Nov 12 '18 17:11 mubarik

I was having same issue with MSTEST

mubarik avatar Nov 12 '18 17:11 mubarik

I would recommend opening a new issue rather than commenting on a closed issue. "omnisharp.path": "latest" would no longer be necessary or recomended, so I would restore that back to the default if you haven't already. Also, I am not sure if this is your problem, but the LiveShare extension cause a similar sounding issue. So if you have that installed, I would recommend trying without it.

gregg-miskelly avatar Nov 12 '18 19:11 gregg-miskelly

LiveShare is not installed. my VSCODE version is Version: 1.28.2. I restored back to default. didn't help

mubarik avatar Nov 12 '18 21:11 mubarik

Please open a new issue so that folks can try and help investigate.

gregg-miskelly avatar Nov 12 '18 21:11 gregg-miskelly