netcoredbg icon indicating copy to clipboard operation
netcoredbg copied to clipboard

Location missing if unhandled Exception occurred in async Main

Open itn3000 opened this issue 2 years ago • 2 comments

Overview

Cannot get location of unhandled exception occurred in async Main program.

Environment

  • netcoredbg version: 3.0.0-13 (27606c3, Release)
  • os: win10 x64
  • dotnet-sdk: 8.0.200
  • vscode: 1.86.2
  • C# extension: 2.18.16

Steps to reproduce

  1. create new console project
  2. open project with vscode
  3. write following code
  4. start vscode debugging session with following pipeTransport setting

code example

using System;
using System.Threading.Tasks;

class Program
{
    static void Abc()
    {
        throw new Exception();
    }
    static async Task Main()
    {
        await Task.Yield();
        Abc();
    }
}

pipeTransport setting

            "pipeTransport": {
                "pipeCwd": "${workspaceFolder}",
                "pipeProgram": "c:/Windows/System32/cmd.exe",
                "pipeArgs": ["/c"],
                "debuggerPath": "d:/bin/netcoredbg/netcoredbg.exe"
            }

Expected

program stops and display exception message.

Actual

program stopped but no message. callstack information is "Unknown Source"

Additional Information

edit Main function to sync, it works as expected.

itn3000 avatar Feb 28 '24 02:02 itn3000

Thanks for reporting, we'll take a look

gbalykov avatar Feb 28 '24 10:02 gbalykov

Looks like async methods should care about exceptions in another way:

<- (E) {"body":{"allThreadsStopped":true,"reason":"exception","text":"An unhandled exception of type 'System.Exception' occurred in System.Private.CoreLib.dll","threadId":93289},"event":"stopped","seq":"14","type":"event"}

plus, in this case we have some "exception handler" (not user code) Screenshot 2024-02-28 235650 in the same time, if I click on top frame, I see proper exception data: Screenshot 2024-02-29 001547

For example, MS C# debugger:

<- (E) {"seq":28,"type":"event","event":"stopped","body":{"reason":"exception","threadId":93792,"text":"An exception of type 'System.Exception' occurred in vscode_test.dll but was not handled in user code","allThreadsStopped":true,"source":{"name":"Program.cs","path":"/home/viewizard/Desktop/projects_test/vscode_test/Program.cs"},"line":8,"column":9}}

Screenshot 2024-02-29 001147

viewizard avatar Feb 28 '24 21:02 viewizard