muhammadsammy / free-vscode-csharp

Free/Libre fork of the official C# extension for vscode

Home Page:https://open-vsx.org/extension/muhammad-sammy/csharp

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Cannot debug webapi projects

dmbaker90 opened this issue · comments

Issue Description

Cannot debug webapi projects. For some reason I can debug Startup.cs, but then it crashes, I can't get to a point where I can debug a Controller endpoint. dotnet run works fine without debugging. I'm not sure if I'm doing something wrong.

Steps to Reproduce

  1. dotnet new webapi
  2. code .
  3. Generate launch.json

Launch.json:

{
    "version": "0.2.0",
    "configurations": [
        {
            "name": ".NET Core Launch (console)",
            "type": "coreclr",
            "request": "launch",
            "preLaunchTask": "build",
            "program": "${workspaceFolder}/bin/Debug/net5.0/webapi-test.dll",
            "args": [],
            "cwd": "${workspaceFolder}",
            "stopAtEntry": false,
            "console": "internalConsole"
        },
        {
            // Use IntelliSense to find out which attributes exist for C# debugging
            // Use hover for the description of the existing attributes
            // For further information visit https://github.com/OmniSharp/omnisharp-vscode/blob/master/debugger-launchjson.md
            "name": ".NET Core Launch (web)",
            "type": "coreclr",
            "request": "launch",
            "preLaunchTask": "build",
            // If you have changed target frameworks, make sure to update the program path.
            "program": "${workspaceFolder}/bin/Debug/net5.0/webapi-test.dll",
            "args": [],
            "cwd": "${workspaceFolder}",
            "stopAtEntry": false,
            // Enable launching a web browser when ASP.NET Core starts. For more information: https://aka.ms/VSCode-CS-LaunchJson-WebBrowser
            "serverReadyAction": {
                "action": "openExternally",
                "pattern": "\\bNow listening on:\\s+(https?://\\S+)"
            },
            "env": {
                "ASPNETCORE_ENVIRONMENT": "Development"
            },
            "sourceFileMap": {
                "/Views": "${workspaceFolder}/Views"
            }
        },
        {
            "name": ".NET Core Attach",
            "type": "coreclr",
            "request": "attach"
        }
    ]
}

tasks.json:

{
    "version": "2.0.0",
    "tasks": [
        {
            "label": "build",
            "command": "dotnet",
            "type": "process",
            "args": [
                "build",
                "${workspaceFolder}/webapi-test.csproj",
                "/property:GenerateFullPaths=true",
                "/consoleloggerparameters:NoSummary"
            ],
            "problemMatcher": "$msCompile"
        },
        {
            "label": "publish",
            "command": "dotnet",
            "type": "process",
            "args": [
                "publish",
                "${workspaceFolder}/webapi-test.csproj",
                "/property:GenerateFullPaths=true",
                "/consoleloggerparameters:NoSummary"
            ],
            "problemMatcher": "$msCompile"
        },
        {
            "label": "watch",
            "command": "dotnet",
            "type": "process",
            "args": [
                "watch",
                "run",
                "${workspaceFolder}/webapi-test.csproj",
                "/property:GenerateFullPaths=true",
                "/consoleloggerparameters:NoSummary"
            ],
            "problemMatcher": "$msCompile"
        }
    ]
}

Expected Behavior

Debugger should launch. Debugger should stay running and hit breakpoints in Controller.

Actual Behavior

Debugger launches, hit's breakpoints in Startup.cs, then stops working. Code stops running. Browser auto opens http://localhost:5000/ but the server already stopped running.

Logs

OmniSharp log

Starting OmniSharp server at 11/2/2021, 7:29:56 PM Target: /home/davidb/playground/webapi-test

OmniSharp server started.
Path: /home/davidb/.vscode-oss/extensions/muhammad-sammy.csharp-1.23.16/.omnisharp/1.37.16/run
PID: 12337

Starting OmniSharp on manjaro 0.0 (x64)
info: OmniSharp.Services.DotNetCliService
Checking the 'DOTNET_ROOT' environment variable to find a .NET SDK
info: OmniSharp.Services.DotNetCliService
DotNetPath set to /usr/share/dotnet/dotnet
info: OmniSharp.MSBuild.Discovery.MSBuildLocator
Located 1 MSBuild instance(s)
1: StandAlone 17.0.0 - "/home/davidb/.vscode-oss/extensions/muhammad-sammy.csharp-1.23.16/.omnisharp/1.37.16/omnisharp/.msbuild/Current/Bin"
info: OmniSharp.MSBuild.Discovery.MSBuildLocator
MSBUILD_EXE_PATH environment variable set to '/home/davidb/.vscode-oss/extensions/muhammad-sammy.csharp-1.23.16/.omnisharp/1.37.16/omnisharp/.msbuild/Current/Bin/MSBuild.exe'
info: OmniSharp.MSBuild.Discovery.MSBuildLocator
Registered MSBuild instance: StandAlone 17.0.0 - "/home/davidb/.vscode-oss/extensions/muhammad-sammy.csharp-1.23.16/.omnisharp/1.37.16/omnisharp/.msbuild/Current/Bin"
CscToolExe = csc.exe
MSBuildToolsPath = /home/davidb/.vscode-oss/extensions/muhammad-sammy.csharp-1.23.16/.omnisharp/1.37.16/omnisharp/.msbuild/Current/Bin
CscToolPath = /home/davidb/.vscode-oss/extensions/muhammad-sammy.csharp-1.23.16/.omnisharp/1.37.16/omnisharp/.msbuild/Current/Bin/Roslyn
BypassFrameworkInstallChecks = true
MSBuildExtensionsPath = /home/davidb/.vscode-oss/extensions/muhammad-sammy.csharp-1.23.16/.omnisharp/1.37.16/omnisharp/.msbuild
info: OmniSharp.WorkspaceInitializer
Invoking Workspace Options Provider: OmniSharp.Roslyn.CSharp.Services.CSharpFormattingWorkspaceOptionsProvider, Order: 0
info: OmniSharp.WorkspaceInitializer
Invoking Workspace Options Provider: OmniSharp.Roslyn.CSharp.Services.Completion.CompletionOptionsProvider, Order: 0
info: OmniSharp.WorkspaceInitializer
Invoking Workspace Options Provider: OmniSharp.Roslyn.CSharp.Services.RenameWorkspaceOptionsProvider, Order: 100
info: OmniSharp.WorkspaceInitializer
Invoking Workspace Options Provider: OmniSharp.Roslyn.CSharp.Services.ImplementTypeWorkspaceOptionsProvider, Order: 110
info: OmniSharp.WorkspaceInitializer
Invoking Workspace Options Provider: OmniSharp.Roslyn.CSharp.Services.BlockStructureWorkspaceOptionsProvider, Order: 140
info: OmniSharp.Cake.CakeProjectSystem
Detecting Cake files in '/home/davidb/playground/webapi-test'.
info: OmniSharp.Cake.CakeProjectSystem
Could not find any Cake files
info: OmniSharp.MSBuild.ProjectSystem
No solution files found in '/home/davidb/playground/webapi-test'
info: OmniSharp.MSBuild.ProjectManager
Queue project update for '/home/davidb/playground/webapi-test/webapi-test.csproj'
info: OmniSharp.Script.ScriptProjectSystem
Detecting CSX files in '/home/davidb/playground/webapi-test'.
info: OmniSharp.Script.ScriptProjectSystem
Could not find any CSX files
info: OmniSharp.WorkspaceInitializer
Configuration finished.
info: OmniSharp.Stdio.Host
Omnisharp server running using Stdio at location '/home/davidb/playground/webapi-test' on host 12212.
info: OmniSharp.MSBuild.ProjectManager
Loading project: /home/davidb/playground/webapi-test/webapi-test.csproj
info: OmniSharp.MSBuild.ProjectManager
Successfully loaded project file '/home/davidb/playground/webapi-test/webapi-test.csproj'.
info: OmniSharp.MSBuild.ProjectManager
Adding project '/home/davidb/playground/webapi-test/webapi-test.csproj'
info: OmniSharp.MSBuild.ProjectManager
Update project: webapi-test
Received response for /v2/getcodeactions but could not find request.
Received response for /findusages but could not find request.
Received response for /v2/codestructure but could not find request.
Received response for /v2/codestructure but could not find request.

C# log

Environment information

VSCode version: 1.61.0
C# Extension: 1.23.16

Mono Information OmniSharp using built-in mono
Dotnet Information .NET SDK (reflecting any global.json): Version: 5.0.205 Commit: 64a0cf25eb

Runtime Environment:
OS Name: manjaro
OS Version:
OS Platform: Linux
RID: arch-x64
Base Path: /usr/share/dotnet/sdk/5.0.205/

Host (useful for support):
Version: 5.0.8
Commit: 42ac4d6d5a

.NET SDKs installed:
5.0.205 [/usr/share/dotnet/sdk]

.NET runtimes installed:
Microsoft.AspNetCore.App 5.0.8 [/usr/share/dotnet/shared/Microsoft.AspNetCore.App]
Microsoft.NETCore.App 5.0.8 [/usr/share/dotnet/shared/Microsoft.NETCore.App]

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

Visual Studio Code Extensions
Extension Author Version
csharp muhammad-sammy 1.23.16

Hi,

I get a similar problem when debugging as Asp.Net Core web application.

I was able to hit a break point set in Program.cs but after I continue running the application seems to crash.

It opens the browser with http://localhost:5000/ but unreachable.

The code is simply:

var builder = WebApplication.CreateBuilder(args);
var app = builder.Build();

app.MapGet("/", () => DateTime.Now.Ticks.ToString());

app.Run();

The launch config used was:

 {
            "name": ".NET Core Launch (web)",
            "type": "coreclr",
            "request": "launch",
            "preLaunchTask": "build",
            "program": "${workspaceFolder}/bin/Debug/net8.0/console.dll",
            "args": [],
            "cwd": "${workspaceFolder}",
            "stopAtEntry": false,
            "serverReadyAction": {
                "action": "openExternally",
                "pattern": "\\bNow listening on:\\s+(https?://\\S+)"
            },
            "env": {
                "ASPNETCORE_ENVIRONMENT": "Development"
            },
            "sourceFileMap": {
                "/Views": "${workspaceFolder}/Views"
            }
        },

Any help will be appreciated - TIA!