How to debug using Rider/VS Code?

Created at 01 Nov 2022, 09:53
How’s your experience with the cTrader Platform?
Your feedback is crucial to cTrader's development. Please take a few seconds to share your opinion and help us improve your trading experience. Thanks!
Waxy's avatar

Waxy

Joined 12.05.2015

How to debug using Rider/VS Code?
01 Nov 2022, 09:53


From the guides I've seen to debug for the new version of cTrader I see we must declare

System.Diagnostics.Debugger.Launch();

However, this only prompts me to select Visual Studio.

Is there a way to debug with these other IDEs and the new cTrader? 

Regards,


@Waxy
Replies

Spotware
01 Nov 2022, 11:43

Hi Waxy,

At the moment only Visual Studio is supported for debugging,

Best regards,

cTrader Team


@Spotware

Waxy
01 Nov 2022, 20:31

Hello Spotware,

Thanks for your answer, and I may take the opportunity to ask to also give us the option soon to choose whether to open by default in visual studio or these other 2 IDEs, VsCode or Rider.

Thanks for your support,
Regards,


@Waxy

MaRCHeW
06 Nov 2022, 20:08

RE:

Spotware said:

Hi Waxy,

At the moment only Visual Studio is supported for debugging,

Best regards,

cTrader Team

Hi Guys,

Thanks for providing support for other IDEs than VS, but debugging is also crucial. Do you have plans to add it in the upcoming releases?

Best Regards

MaRCHeW

 

 


@MaRCHeW

Waxy
02 Feb 2024, 00:27 ( Updated at: 02 Feb 2024, 06:41 )

I figured out how to debug with rider.

"Settings | Build, Execution, Deployment | Debugger" and click "Set Rider as a default debugger"

It should prompt you to use Rider for debugging.

Allow JIT Rider Debugging Session to be Started with Debugger.Launch() : RIDER-18701 (jetbrains.com)

Regards,


@Waxy

delaghetto
21 Feb 2024, 22:12 ( Updated at: 22 Feb 2024, 07:46 )

You can also debug in VS code.

First build the project in Debug mode, so:

dotnet build -c Debug

Now you need to have a launch.json configuration file, with debugging instructions. This can be automatically generated:

  1. Run - Add configuration. The first time it will prompt you to select a debugger, you must choose c#. This will generate the launch.json file
  2. Now again, Run - Add configuration; this time you must choose the option that says .NET: Attach to .NET proccess

So once you do this, the final launch.json will look something like this:

 

{

    // Use IntelliSense to learn about possible attributes.

    // Hover to view descriptions of existing attributes.

    // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387

    "version": "0.2.0",

    "configurations": [

        {

            "name": ".NET Core Attach",

            "type": "coreclr",

            "request": "attach"

        }

    ]

}

Now for actually debuging, you must first go to cTrader, and add an instance of your bot or indicator, and run it. Once you run it, there will be a new Windows proccess created, so if you go back to VS Code, and do Run - Start Debugging, you will be able to attach the debugger to the proccess, which will be algohost.exe; you may have multiple algohost.exe, so make sure you hover on top of each one, and look for the one that corresponds to your bot. 

You can now set you breakpoints in code, and when you go back to cTrader, you can stop and restart the instance of your bot as many times as you need, and will be able to debug in VS Code.


@delaghetto