Debug C# with VSCode

Hello, I’m trying to debug a C# script with VSCode, the breakpoints stop the Flax editor but not in VSCode.

More or less I’ve followed the manual:

  • installed latest VSCode and needed extension
  • compiled Flax with Editor.Development for Win64
  • launched the Editor with -debug 127.0.0.1:55555 (so no need to change the VSCode launch.json file)
  • opened the FirstPersonShooterTemplate example
  • double click on the file Source\FirstPersonShooter\PlayerScript.cs
  • in VSCode put a breakpoint in OnUpdate at the Shoot lines
  • pressed Start Debugging with “FirstPersonShooter (C# attach)|Editor.Windows.Development|x64” (but they all seem the same)
  • now I see two threads and the Finalizer running
  • back in the Editor, pressed Start Game
  • the game runs
  • pressed mouse to shoot, the editor freezes (correctly, like if it has hit the breakpoint)
  • back in VSCode, the breakpoint is not hit, the threads are still running, the Pause button does not work
  • pressed Disconnect, the editor goes back to running

It seems like this:


but this was already solved.

Do you have any pointers? Does the Mono debugger have a log?
Different topic, how can we debug the editor? in the same way?
thanks

I tested VS Code 1 or 2 months ago and it worked well like in this tutorial:

I would suggest using -monolog cmd line switch on Editor so it will print the full verbose log of the Mono (docs: https://docs.flaxengine.com/manual/editor/advanced/command-line-access.html). Maybe it will say sth.

Nothing interesting about the debugger with “monolog”.
However I get a ton of:
[ 00:00:04.019 ]: [Info] Message: Probing ‘_RegQueryValueExWW@48’. | Domain: Mono
[ 00:00:04.019 ]: [Info] Message: Could not find ‘_RegQueryValueExWW@48’ due to 'The specified procedure could not be found.
Maybe it is the double W.

Do you debug from VS Code on Windows or Linux ?

Windows 8.1.
Visual Studio with the Flax plugin works very well.

I’ve added the debugger “logfile” option to the mono_jit_parse_options function.
I don’t think I can upload a text/zip file here, so this is its interesting part:

...
[dbg] Inserted breakpoint at PlayerScript:OnUpdate ():[il=0x8e,native=0x3e4] [0000009042A2E0C4](0).
[0000000000004E88] Breakpoint hit, method=OnUpdate, ip=0000009042A2E0D5, [il=0x8e,native=0x3f5].
[0000000000004E88]   send method [PlayerScript:OnUpdate ()]
[0000000000004E88] Suspending vm...
[0000000000004E88] Interrupting 000000000000486C...
[00000000000055DC] Received single step event for suspending.
[000000000000486C] Received interrupt while at 00007FFB4E92079A, treating as suspended.
[0000000000004E88] Interrupting 00000000000055DC...
[00000000000055DC] Suspended.
[0000000000004E88] Sent 1 events BREAKPOINT(17), suspend=2.
[0000000000004E88] Suspended.
[dbg] Command THREAD(GET_FRAME_INFO) [97][at=19e1f].
Frames for 000000904A440130(tid=4e88):
	Frame: PlayerScript:OnUpdate ():[il=0x8e, native=0x3f5] 1
[dbg]   send method [PlayerScript:OnUpdate ()]
[dbg] Command MODULE(GET_INFO) [98][at=19e29].
[dbg]   send assembly [FirstPersonShooter.CSharp][Flax][11]
[dbg] Command EVENT_REQUEST(REQUEST_CLEAR) [99][at=1b7fb].
[dbg] Clear breakpoint at PlayerScript:OnUpdate () [0000009042A2E0C4].
[dbg] transport_recv () returned 0, expected 11.
[dbg] Command VM(DISPOSE) [0][at=1b800].
[0000000000002DB8] Resuming vm, suspend count=0...
[00000000000055DC] Resumed.
[0000000000004E88] Resumed.
[dbg] Debugger thread exited.
[dbg] Detached - restarting clean debugger thread.
[dbg] Agent thread started, pid=00000000000072AC
...

So I think the breakpoint is set and it is hit, no problems. Something does not work on my VSCode.

Thanks for the log. I think you’re right, it’s more like related to Mono Debugger. Also, we use Mono 5.20.1 so maybe the newest debugger extension might have a bug or something.