microsoft / VSDebugAdapterHost

Visual Studio Debug Adapter Host
MIT License
74 stars 20 forks source link

Getting Error of "Failed to launch debug adapter 'App'. No such host is known" when running wiki test. #18

Open CartBlanche opened 2 years ago

CartBlanche commented 2 years ago

I'm trying to host an existing VSCode extension, that talks to an IoT device inside VS2019 or VS for Mac and I'm getting the error mentioned in the subject line.

The VSCode extension is able to set breakpoints and debug apps running on the device (a Meadow F7 Micro) if I run it from VS Code itself, but when I run the test mentioned on your wiki, in VS2019, the error above appears.

Now on Windows the IoT device is connected via USB and appears on COM5. So I'm assuming that I should have "$debugServer": "COM5", in my launch.json? Is that correct?

What else is required for this scenario to work?

My full launch.json looks like this... `{ "$debugServer": "COM5", "$adapter": "C:\[Path to VS Code exe]\vscode-meadow.exe",

"type": "App",
"request": "launch",
"program": "C:\\[Path to Source File]\\MeadowApp.cs"

}`

andrewcrawley commented 2 years ago

Hey, @CartBlanche

You shouldn't need the $debugServer property - it's intended to specify an alternate way to communicate with a debug adapter, generally for development and testing purposes. In this case, it's asking VS to connect to an already-running instance of the debug adapter on a remote host called "COM5", which ends up producing the error message you're seeing.

In general, you should be able to take a working launch.json from VS Code, add the $adapter property, and run it either via the "Engine Launcher" extension or DebugAdapterHost.Launch command.

You may run into issues if the debug adapter has dependencies on an associated VS Code extension - I don't know anything about Meadow, but their extension readme mentions that it uses VS Code functionality to prompt to choose a serial port, so you might need to add the correct data to your launch.json manually. A quick glance at the debug adapter source suggests that something like "serial": "COM5" may work in your launch.json.

CartBlanche commented 2 years ago

@andrewcrawley Thanks for the quick response. Greatly appreciated!

I think I may need to tweak the VSCode Meadow extension to ensure it is a good DAP citizen, because with your suggested change and re-running the wiki test I now get the following errors...

 1> DebugAdapterHost version: 16.9.50429.2 commit:ca34bde2a8dfef71e1d0b3bafd2804978bfbe6a9
 1> Starting 'C:[Path to VSCode]\vscode-meadow.exe' with arguments ''
 1> WARNING: 'Language' not specified in engine registration!
 1> WARNING: 'LanguageId' not specified in engine registration!
 1> [DebugAdapter] --> C (initialize-1): {"type":"request","command":"initialize","arguments":{"pathFormat":"path","clientID":"visualstudio","clientName":"Visual Studio","adapterID":"App","locale":"en-US","linesStartAt1":true,"columnsStartAt1":true,"supportsVariableType":true,"supportsRunInTerminalRequest":true,"supportsMemoryReferences":true,"supportsProgressReporting":true,"SupportsMessageBox":true,"supportsHandshakeRequest":true,"supportsVsAdditionalBreakpointBinds":true,"supportsHitCountsChange":true,"supportsVsCustomMessages":true,"supportsVariableEnumerators":true},"seq":1}
 1> ERROR: Debug adapter error output: waiting for debug protocol on stdin/stdout
 1> [DebugAdapter] <--   R (initialize-1) [675 ms]: {"type":"response","request_seq":1,"success":true,"command":"initialize","body":{"supportsConfigurationDoneRequest":false,"supportsFunctionBreakpoints":false,"supportsConditionalBreakpoints":false,"supportsEvaluateForHovers":false,"exceptionBreakpointFilters":[]},"seq":1}
 1> WARNING: Debug adapter does not support 'configurationDone' request!
 1> WARNING: Debug adapter does not support value formatting - user-configurable stack trace formatting will be unavailable.
 1> WARNING: Debug adapter does not support 'setVariable' request - all variables will be read-only.
 1> WARNING: Debug adapter does not support 'hover' context for evaluations - unexpected side effects may occur.
 1> [DebugAdapter] --> C (launch-2): {"type":"request","command":"launch","arguments":{"serial":"COM5","type":"App","request":"launch","program":"C:[Path to Source File\MeadowApp.cs"},"seq":2}
 1> [DebugAdapter] <--   E (initialized): {"type":"event","event":"initialized","seq":2}
 1> [DebugAdapter] <--   R (initialize-1): {"type":"response","request_seq":1,"success":true,"command":"initialize","body":{"supportsConfigurationDoneRequest":false,"supportsFunctionBreakpoints":false,"supportsConditionalBreakpoints":false,"supportsEvaluateForHovers":false,"exceptionBreakpointFilters":[]},"seq":1}
 1> WARNING: Unable to locate a pending request with type 'initialize' and sequence number '1'!
 1> WARNING: Stopping due to fatal error: InvalidOperationException: Unable to locate a pending request with type 'initialize' and sequence number '1'!
 1> ERROR: Debug Adapter did not respond to initial requests.
 1> ERROR: Unexpected error

AggregateException: One or more errors occurred.

Aggregate exception: 
    DebugAdapterLaunchException: Failed to launch debug adapter.  Additional information may be available in the output window.

    Failure Location: UserCanceled
    Inner Exception: 
        OperationCanceledException: The operation was canceled.
Inner Exception: 
    DebugAdapterLaunchException: Failed to launch debug adapter.  Additional information may be available in the output window.

Microsoft.VisualStudio.Debugger.VSCodeDebuggerHost.Engine.Implementation.DebuggedProcess.<StartDebugAdapter>b__114_3(Exception ex)
Microsoft.VisualStudio.Debugger.VSCodeDebuggerHost.Utilities.TaskExtensions.<>c__DisplayClass11_0`1.<Catch>b__0(TException ex)
Microsoft.VisualStudio.Debugger.VSCodeDebuggerHost.Utilities.TaskExtensions.<>c__DisplayClass10_0`1.<Catch>b__0(AggregateException ex)

    Failure Location: UserCanceled
    Inner Exception: 
        OperationCanceledException: The operation was canceled.

 1> ERROR: One or more errors occurred.

Failed to launch debug adapter.  Additional information may be available in the output window.

The operation was canceled.
 1> Debug adapter process exited.
 1> ERROR: Exception thrown while handling debug adapter exit!

InvalidOperationException: Operation not allowed on dispatcher thread!

Microsoft.VisualStudio.Shared.VSCodeDebugProtocol.Protocol.DebugProtocol.VerifySynchronousOperationAllowed()
Microsoft.VisualStudio.Debugger.VSCodeDebuggerHost.Engine.Implementation.DebuggedProcess.OnDebugAdapterExit(Object sender, EventArgs e)

 1> ERROR: Unexpected error

InvalidOperationException: Unable to locate a pending request with type 'initialize' and sequence number '1'!

Microsoft.VisualStudio.Shared.VSCodeDebugProtocol.Protocol.DebugProtocol.HandleIncomingResponse(String msg)
Microsoft.VisualStudio.Shared.VSCodeDebugProtocol.Protocol.DebugProtocol.HandleIncomingMessage(String msg)
Microsoft.VisualStudio.Shared.VSCodeDebugProtocol.Protocol.DebugProtocol.ProcessMessageBody()
Microsoft.VisualStudio.Shared.VSCodeDebugProtocol.Protocol.DebugProtocol.ReaderThreadProc()

 1> ERROR: Unable to locate a pending request with type 'initialize' and sequence number '1'!
 1> WARNING: Cannot send message when the protocol dispatcher is not running.

If I fix the warning for the missing thins like configurationDone etc, do you think that will stop the Debug Adapter did not respond to initial requests. error or is there more I'm missing? Apologies for these newbie questions, I'm just trying to understand what it takes for a VSCode implementation to work "out of the box" with VS2019/VS022 :)

andrewcrawley commented 2 years ago

It's failing because of the duplicate response to the initialize request, so I'd start there. The other warnings are mostly about things the adapter could do to better integrate with VS, so they should be OK to ignore until the basic scenario is working.

CartBlanche commented 2 years ago

@andrewcrawley I just wanted to Thank you for all your help so far, before the year is out :) I've had to focus on native VS extension releases up until now, but the plan is to switch focus to migrating the VSCode extension, so we can reuse it in both VS 4 Windows and VS 4 Mac and therefore have just 1 debugging interface to maintain going forward. Thanks again and hopefully I won't need to hassle you in the new year :)

adityaaswani commented 2 years ago

We also faced this issue. We were getting 2 responses for initialize request. 1 was generated by the DebugAdapter while the other was actually returned by the debugger.

FrankSzendzielarz commented 1 year ago

I am working on a custom DA for VS now and finding things a bit obscure.... how did you find the $debugServer property above, and where are such things documented? Right now I am trying to get DebugAdapterHost.Launch to use an existing running DA, on a port, and it looks like that's what i need...

andrewcrawley commented 1 year ago

Hey, @FrankSzendzielarz - the special properties recognized by the VS debug adapter host are documented here: https://github.com/microsoft/VSDebugAdapterHost/wiki/Special-Properties-Recognized-by-the-Debug-Adapter-Host

FrankSzendzielarz commented 1 year ago

Hey, @FrankSzendzielarz - the special properties recognized by the VS debug adapter host are documented here: https://github.com/microsoft/VSDebugAdapterHost/wiki/Special-Properties-Recognized-by-the-Debug-Adapter-Host

Many thanks, Andrew! Very helpful.