Custom Code Break Points & Debugging

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.

  1. Create a new tab (ctrl + t)

  2. Launch the Package Manager dialog

  3. Find and select the Data Generation channel

  4. Click the Install button

  5. Close the Package Manager dialog

image-20250827-005330.png

The channel import dialog will be displayed:

image-20250827-005519.png

Click the Import & Close button, and then the Close button on the Package Manager dialog. Your channel should look similar to this:

image-20250827-005651.png
The channel and custom code device we’ll debug

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.

image-20250827-010140.png

As soon as the break point is created, you’ll be prompted to choose the type of debugging you want.

image-20250827-010624.png

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 in Release mode, and must be switched to Debug mode first. Use this option if the Attach to Server option is disabled.

image-20250827-011338.png
Custom code device is automatically switched to Debug mode, if needed. You can switch it back to release mode by using the yellow bar, or, the Debug hyperlink in the bar above.

A Visual Studio project will be created and launched, and should look similar to this:

image-20250827-180014.png

Load the Custom Device class file, and notice the break point on line 23. You can add your own break points in Visual Studio.

image-20250827-180237.png

Start the channel, and confirm your break point is hit.

image-20250827-180514.png

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.

image-20250827-220207.png

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.