Debugging Unit Test loses codelens Run Test / Debug Test - DebugSessionManager does not stop
Related to #1743
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: 1.0.4 [C:\Program Files\dotnet\sdk] 2.0.2 [C:\Program Files\dotnet\sdk] 2.0.3 [C:\Program Files\dotnet\sdk] 2.1.2 [C:\Program Files\dotnet\sdk] 2.1.3 [C:\Program Files\dotnet\sdk] 2.1.4 [C:\Program Files\dotnet\sdk] 2.1.100 [C:\Program Files\dotnet\sdk] 2.1.101 [C:\Program Files\dotnet\sdk] 2.1.102 [C:\Program Files\dotnet\sdk] 2.1.103 [C:\Program Files\dotnet\sdk] 2.1.104 [C:\Program Files\dotnet\sdk] 2.1.105 [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 1.0.5 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 1.1.2 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 2.0.0 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 2.0.3 [C:\Program Files\dotnet\shared\Microsoft.NETCore.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 PS D:\CBRock\XCellorator>
VS Code version: 1.24.1 C# Extension version: ms-vscode.csharp-1.15.2.omnisharp\1.30.1\OmniSharp.exe
Steps to reproduce
Create a TestServer that has a IHostedService with dependencies and do not perform a graceful close on the TestServer using the following code: this.testServerIam.Host.StopAsync().GetAwaiter().GetResult();. The OmniSharp.DotNetTest.DebugSessionManager will never report "Debug session ended", it will be stuck with "Debug session started.", even though the .NET Test Log says Debugging complete. The extra host process not being cleaned up / shutdown must be confusing omnisharp. In some cases the codelens may appear on a fresh restart but clicking the debug again will just hang with the debug starting in the output window (it will never start).
Expected behavior
Omnisharp debug session stops, codelens run/debug appears and a subsequent debug can be performed.
More food for thought.
When I kill the debug process with the Stop action it sometimes hangs as well as it must not be gracefully closing the TestServer() as it does in the fixtures dispose now.
this.testServerMain = new TestServer(company.app.Main.Program
.GetWebHostBuilder(Path.GetFullPath("../../../../../Src/company.app.Main"), args));
testServerMain.BaseAddress = new Uri("http://acme.localhost:5003");
It seems to be sporadic at not related to changes i have made, it appears to be timing based and some of the changes affected the timing which made it falsely appear to have worked.
On my laptop (slower machine) no matter what i try, it will NOT end the debug session and i cannot debug again until a window reload is performed. Visual Studio Enterprise works just fine. I have hundreds of tests and have not seen this issue until the upgrade to the latest dotnet 2.1.301 version.
If i find anything else i will share, i hope a solution will present itself soon...
Narrowed it down to this in the start of my fixture. It doesn't like starting a new server in another thread. If i just strip my code to start like the sample below and do not call this.ServerMainReal.StopAsync() in the fixture dispose omnisharp will not end the debug process. If i do call the StopAsync() the omnisharp debug will get the command to stop the debugger. This doesn't work if say i have a break point and click stop in the debugger toolbar - i had this problem for a long time whereas i debug a unit test and have a syntax error, i would always have to reload the window in vs code. Now i know it's related to this code.
I'm trying to see if i can not use real servers but the issue is that these servers have api's that use an identity server for token authorization that rely on real endpoints which is why i cannot use the TestServer object.
Any suggestions/ideas would be greatly appreciated. Using a VS Enterprise is not a pleasant option for me...
this.ServerMainReal = company.app.Program
.BuildWebHost(Path.GetFullPath("../../../../../Src/company.app.Main"), argsMain);
this.ServerMainReal.Start();
I have the same issue in VS Code.
In addition to all the other comments here I found this output in the omnisharp log:
/Users/myuser/.vscode/extensions/ms-vscode.csharp-1.15.2/.omnisharp/1.30.1/run: line 50: 65745 Killed: 9 "${MONO_CMD}" "${OMNISHARP_CMD}" "$@"
More interesting information, the issue appears to be linked with running visual studio 2017 enterprise (version info below). I was running fine this morning and then all of sudden i could not re-debug the unit tests (original issue), after an hour or so of troubleshooting it turns out when vs enterprise is running the debug session will not get ended in vs code. Only the integration tests that are starting the TestServer are impacted. I reproduced multiple times, debug an integration test multiple times with VS Enterprise closed and all is fine, launch VSE and debug unit test and OmniSharp.DotNetTest.DebugSessionManager never says Debug session ended. after test is done running.
Microsoft Visual Studio Enterprise 2017 Version 15.7.4 VisualStudio.15.Release/15.7.4+27703.2035 Microsoft .NET Framework Version 4.7.03056
Installed Version: Enterprise
Application Insights Tools for Visual Studio Package 8.12.10405.1 Application Insights Tools for Visual Studio
ASP.NET and Web Tools 2017 15.0.40601.0 ASP.NET and Web Tools 2017
ASP.NET Core Razor Language Services 15.7.31476 Provides languages services for ASP.NET Core Razor.
ASP.NET Web Frameworks and Tools 2017 5.2.60419.0 For additional information, visit https://www.asp.net/
Azure App Service Tools v3.0.0 15.0.40608.0 Azure App Service Tools v3.0.0
Azure Data Lake Node 1.0 This package contains the Data Lake integration nodes for Server Explorer.
Azure Data Lake Tools for Visual Studio 2.3.3000.2 Microsoft Azure Data Lake Tools for Visual Studio
Azure Functions and Web Jobs Tools 15.0.40608.0 Azure Functions and Web Jobs Tools
Azure Stream Analytics Tools for Visual Studio 2.3.3000.2 Microsoft Azure Stream Analytics Tools for Visual Studio
C# Tools 2.8.3-beta6-62923-07. Commit Hash: 7aafab561e449da50712e16c9e81742b8e7a2969 C# components used in the IDE. Depending on your project type and settings, a different version of the compiler may be used.
Common Azure Tools 1.10 Provides common services for use by Azure Mobile Services and Microsoft Azure Tools.
Fabric.DiagnosticEvents 1.0 Fabric Diagnostic Events
JavaScript Language Service 2.0 JavaScript Language Service
Microsoft Azure HDInsight Azure Node 2.3.3000.2 HDInsight Node under Azure Node
Microsoft Azure Hive Query Language Service 2.3.3000.2 Language service for Hive query
Microsoft Azure Service Fabric Tools for Visual Studio 2.2 Microsoft Azure Service Fabric Tools for Visual Studio
Microsoft Azure Stream Analytics Language Service 2.3.3000.2 Language service for Azure Stream Analytics
Microsoft Azure Stream Analytics Node 1.0 Azure Stream Analytics Node under Azure Node
Microsoft Azure Tools 2.9 Microsoft Azure Tools for Microsoft Visual Studio 2017 - v2.9.10420.2
Microsoft Continuous Delivery Tools for Visual Studio 0.3 Simplifying the configuration of continuous build integration and continuous build delivery from within the Visual Studio IDE.
Microsoft JVM Debugger 1.0 Provides support for connecting the Visual Studio debugger to JDWP compatible Java Virtual Machines
Microsoft MI-Based Debugger 1.0 Provides support for connecting Visual Studio to MI compatible debuggers
Microsoft Visual Studio Tools for Containers 1.1 Develop, run, validate your ASP.NET Core applications in the target environment. F5 your application directly into a container with debugging, or CTRL + F5 to edit & refresh your app without having to rebuild the container.
NuGet Package Manager 4.6.0 NuGet Package Manager in Visual Studio. For more information about NuGet, visit http://docs.nuget.org/.
ProjectServicesPackage Extension 1.0 ProjectServicesPackage Visual Studio Extension Detailed Info
ResourcePackage Extension 1.0 ResourcePackage Visual Studio Extension Detailed Info
SonarLint for Visual Studio 4.1.0.3539 SonarLint is an extension to your favorite IDE that provides on-the-fly feedback to developers on new bugs and quality issues injected into their code.
SQL Server Data Tools 15.1.61804.210 Microsoft SQL Server Data Tools
ToolWindowHostedEditor 1.0 Hosting json editor into a tool window
TypeScript Tools 15.7.20419.2003 TypeScript Tools for Microsoft Visual Studio
Visual Basic Tools 2.8.3-beta6-62923-07. Commit Hash: 7aafab561e449da50712e16c9e81742b8e7a2969 Visual Basic components used in the IDE. Depending on your project type and settings, a different version of the compiler may be used.
Visual F# Tools 10.1 for F# 4.1 15.7.0.0. Commit Hash: 173513e369ffb7a1c4d5dccf83696d9aac2ab2d0. Microsoft Visual F# Tools 10.1 for F# 4.1
Visual Studio Code Debug Adapter Host Package 1.0 Interop layer for hosting Visual Studio Code debug adapters in Visual Studio
FYI, the reason I use VSE as part of my daily routine is for code coverage and it's nice test runner.
More interesting information, the issue appears to be linked with running visual studio 2017 enterprise (version info below).
I cannot confirm. I'm experiencing this issue on a Mac having no VSE installed/running.
I am getting this issue with VS Code on a Mac too. Have you guys found a fix? The only way I have is to restart VS Code. Thanks
@akshita31 : Do you have any thoughts here? It seems like something we could address.
@DustinCampbell I made a fix to omnisharp-roslyn that handles a problem with the debug session : https://github.com/OmniSharp/omnisharp-roslyn/pull/1239. I believe this issue should be fixed by that.
@xcellsoft Can you try installing the latest beta by following these instructions and checking if the error still reproduces ?
I just tried with the latest beta and it did not fixed it for me. Let me know if there is any info or test I could run that could help.
@vhetet Can you provide some more repro steps.
@akshita31 So I run or debug a test and it will work fine the first time. But after the test end I see this in the omnisharp log.
/Users/vhetet/.vscode/extensions/ms-vscode.csharp-1.16.0-beta1/.omnisharp/1.32.2/run: line 28: 72415 Killed: 9 "${mono_cmd}" "${omnisharp_cmd}" "$@"
After that run and debug don't work and I need to restart VSCode
The steps are basically run a unit test, and check the omnisharp log for the above error. Keep running the test until you see it.
Notes: It may be necessary to run/debug a few time before it crashes
Here is the my dotnet environment info .NET Core SDK (reflecting any global.json): Version: 2.1.301 Commit: 59524873d6
Runtime Environment: OS Name: Mac OS X OS Version: 10.13 OS Platform: Darwin RID: osx.10.13-x64 Base Path: /usr/local/share/dotnet/sdk/2.1.301/
Host (useful for support): Version: 2.1.1 Commit: 6985b9f684
.NET Core SDKs installed: 2.1.300 [/usr/local/share/dotnet/sdk] 2.1.301 [/usr/local/share/dotnet/sdk]
.NET Core runtimes installed: Microsoft.AspNetCore.All 2.1.0 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.All] Microsoft.AspNetCore.All 2.1.1 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.All] Microsoft.AspNetCore.App 2.1.0 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 2.1.1 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App] Microsoft.NETCore.App 2.1.0 [/usr/local/share/dotnet/shared/Microsoft.NETCore.App] Microsoft.NETCore.App 2.1.1 [/usr/local/share/dotnet/shared/Microsoft.NETCore.App]
To install additional .NET Core runtimes or SDKs: https://aka.ms/dotnet-download
Let me know if there is any other info that could be useful.
@akshita31 have you been able to look at that?
It keep crashing and I have to restart VSCode every time. It's really a pain. Thanks
Sorry, I haven't been monitoring this thread lately.
I did apply the beta awhile back which helped with some issues like the syntax error problem where you'd have to restart VSCode. But it seemed to cause more frequent sporadic issues i removed the beta.
There are still some issues relating to this original thread. A few times a day at least i'll start a unit test debug and it'll it just hang there and i'll have to restart vscode. In some cases i'll get the double, tripple, etc... debuggers starting which also requires a restart.
I run into this quite a bit as i have 1000+ tests in my code base...
If I encounter a reproducible scenario again i will post.
@DustinCampbell I'm pretty sure the issue here is that running the test host under the debugger causes it to send bad/unexpected messages to OmniSharp, which then crashes. Note that this only happens when OmniSharp is running under mono. I've been having trouble getting the VS Code mono debugger to break on exceptions. Do you have any debugging strategies you would recommend?
It's tough getting it reproducible on demand. I'll keep working on it - really busy on a big project.
With the beta build I'm having a common issue a couple times a day. Just had it now. I feel i have less issues with the non-beta version. The syntax error bug with the unit tests appears to be fixed so it's a trade off now.
Was debugging a unit test to see the outcome of some variables being populated and then I just stopped it with the debug toolbar, now all the intellisense is disabled and i cannot click F12 to go to class definitions (i can only get back intellisense on reboot, this seems a common issue with the beta). The progress indicator is showing on the editor:

...and the omnisharp log shows whereas there is no "Debug session ended":
[info]: OmniSharp.DotNetTest.VSTestManager
read: {"MessageType":"TestSession.Connected","Payload":null}
[info]: OmniSharp.DotNetTest.VSTestManager
read: {"MessageType":"ProtocolVersion","Payload":1}
[info]: OmniSharp.DotNetTest.DebugSessionManager
Debug session started.
@DustinCampbell Can you help us here: https://github.com/OmniSharp/omnisharp-vscode/issues/2398#issuecomment-417413477. There are similar issues that are getting a lot of traction : https://github.com/OmniSharp/omnisharp-vscode/issues/2106
Same issue here on my mac.
Runtime Environment:
OS Name: Mac OS X
OS Version: 10.13
OS Platform: Darwin
RID: osx.10.13-x64
Base Path: /usr/local/share/dotnet/sdk/2.1.401/
Host (useful for support):
Version: 2.1.3
Commit: 124038c13e
.NET Core SDKs installed:
1.1.10 [/usr/local/share/dotnet/sdk]
2.1.4 [/usr/local/share/dotnet/sdk]
2.1.300-preview1-008174 [/usr/local/share/dotnet/sdk]
2.1.300-preview2-008533 [/usr/local/share/dotnet/sdk]
2.1.300 [/usr/local/share/dotnet/sdk]
2.1.401 [/usr/local/share/dotnet/sdk]
C# Extension 1.16.0
- Run test
- Debug test with breakpoint for which I hit F5 to continue
- Code lens dies and I have to restart VS Code
Note that restarting OmniSharp does not help here. You need to actually restart VS Code.
@rchande @akshita31 Want me to come up with a repro project?
Edit: This is my package references.
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.7.0" />
<PackageReference Include="NSubstitute " Version="3.1.0" />
<PackageReference Include="Shouldly" Version="3.0.0" />
<PackageReference Include="xunit" Version="2.3.1" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.3.1" />
<DotNetCliToolReference Include="dotnet-xunit" Version="2.3.1" />
Okay, I have tested this with the simplest project possible.
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netcoreapp2.1</TargetFramework>
<IsPackable>false</IsPackable>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.8.0" />
<PackageReference Include="xunit" Version="2.3.1" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.3.1" />
</ItemGroup>
</Project>
My test class looks like this
using System;
using Xunit;
namespace DebugTest
{
public class UnitTest1
{
[Fact]
public void ShouldBeOk()
{
}
}
}
Repro step(s)
Hit Debug Test (code lens) once. Once that is finished, code lens is broken and no language services from OmniSharp are working.