vscode-csharp: 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.

About this issue

  • Original URL
  • State: open
  • Created 6 years ago
  • Reactions: 2
  • Comments: 57 (8 by maintainers)

Most upvoted comments

Still exists as an issue for me as well.

@rchande @akshita31 @vhetet

I discovered something that might be useful.

In the repro project https://github.com/seesharper/Omnisharp-WebApi

If I run the test with the solution loaded, meaning both the test project and the webapi project, the test causes death to OmniSharp. Note that the test project does not even reference the web api project.

Now, If I open ONLY the test project, the test runs fine in debug mode.

So maybe it is related to what assemblies are being fed into the debugger or something in that direction?

When I think about this, the problem has been mostly prominent on project involving AspNetCore

UPDATE.

I managed to get it to fail even when loading just the test project, but I had to run the test(debug) like 20 times for it to fail. Could it be a memory thing? Or simply a timing issue somewhere?

FYI, mine still crashes all the time (windows) - i’m now really efficient at hitting Ctrl-P + Reload Window, I keep updating to the next beta’s in hope it gets fixed. I wish i had more time to troubleshoot the exact the issue to help solve the problem. I lose the debugger on certain exceptions thrown when debugging, also when stopping the debugger in certain situations, and then about half the time on syntax errors when trying to debug.

I’m currently running

OmniSharp server started. Path: C:\Users\ChrisBaird.AzureAD.vscode\extensions\ms-vscode.csharp-1.17.0-beta2.omnisharp\1.32.5\OmniSharp.exe PID: 27996

Tried the “trick” of @seesharper to do a complete uninstall on Linux (ubuntu 18.04-x64, dotnet-sdk: 2.1.402, VSCode 1.27.2, Omnisharp-vscode 1.16.1) but this did not solve the issue. The extension still crashes on completion of the unit-test with the log-line:

/home/henrik/.vscode/extensions/ms-vscode.csharp-1.16.1/.omnisharp/1.32.5/run: line 28: 22949 Killed “${mono_cmd}” “${omnisharp_cmd}” “$@”

As a result of the crash the complete Omnisharp feature is no longer available in VSCode. Also restarting Omnisharp or selecting the solution again does not restore the Omnisharp experience. Only a full restart of VSCode does the trick - which is more than just annoying.

Also tried the latest beta (v1.17.0-beta2) but this only helps for the mono/BOM issue resulting in the red-flame.

Just tried: the described behavior is not present in Windows where one can happily debug a test.

@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

I’m still experiencing this issue, VS Code 1.73.1. I have to restart my computer to get the run test/debug test options to show!

Just stop the debugger when unhandled exception is thrown will solve the problem. Just don’t “continue” the debugger.

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.