Custom Code Break Points & Debugging
The custom code control supports break points and debugging (via Visual Studio or another IDE) in most scenarios within Connexion. This is also supported in some scenarios on the Gateway, but is not supported on Remote Agents.
This feature requires Visual Studio (or another IDE) installed on the same machine as Connexion.
This feature relies heavily on Visual Studio automation. When creating break points for debugging, the Connexion UI application creates a C# project, adds each item within your custom code control (code files, references, resources, etc.), attaches the Visual Studio debugger to the process hosting your control, and then adds all break points.
Custom Code Device Tutorial
In this tutorial, we’ll debug a custom code device by adding a break point and stepping through the code in Visual Studio.
Let’s start by using installing the Data Generation sample channel from the Conevity samples repository.
Create a new tab (
ctrl + t)Launch the
Package ManagerdialogFind and select the
Data GenerationchannelClick the
InstallbuttonClose the
Package Managerdialog
The channel import dialog will be displayed:
Click the Import & Close button, and then the Close button on the Package Manager dialog. Your channel should look similar to this:
In the area to the left of line 23 (to the left of the line number), click your mouse, or, place the text caret on line 23 and hit the F9 key.
If the management UI isn’t running elevated, you’ll be prompted to restart it. Click yes to automatically restart the UI. You will need to recreate the break point after the application reloads.
As soon as the break point is created, you’ll be prompted to choose the type of debugging you want.
There are 3 options:
Attach to User Interface: This attaches the debugger to the management application, and is only used when debugging a message hosted within the client. You would only use this option if you have a sophisticated device which supports previewing message changes.Attach to Server: Attach to the Connexion process hosting your channel. If your custom code device is already in Debug mode, then this option will be enabled. This is typically the option you want.Switch to Debug & Attach: Attach to the Connexion process hosting your channel. Your custom code device is running inReleasemode, and must be switched toDebugmode first. Use this option if theAttach to Serveroption is disabled.
Debug hyperlink in the bar above. A Visual Studio project will be created and launched, and should look similar to this:
Load the Custom Device class file, and notice the break point on line 23. You can add your own break points in Visual Studio.
Start the channel, and confirm your break point is hit.
You can now step through your code within Visual Studio, and utilize the rich debugging tools available.
Note that code changes made within Visual Studio are not tracked, and will be lost when Visual Studio closes. Instead, make your changes within the Custom Code control, and Visual Studio should be automatically updated when you save the channel.
We use Visual Studio automation to synchronize projects and breakpoints between the Connexion UI and Visual Studio. Rarely, an automation call will fail (VS may be busy with some task) and you will need to retry the operation.
For custom code controls which use embedded global tags, and the global variable is multiple lines, an error will be thrown when the break point is created. Use the alternate solution below.
You can also attach the debugger without creating a break point within the custom code control. On the toolbar, there are options to attach and detach the debugger.
When you are finished debugging, you should either close Visual Studio, or, use the Detach option on the toolbar.
If your device is being used in production, remember to switch it from Debug back to Release. Release mode is more performant.