Remote debugging C# code

Because PLCnext Technology includes an implementation of eCLR, you have the option to establish a C# remote session on a PLCnext Control.

This topic describes the basic steps needed for setting up a remote debug session and establishing a direct connection to a running application by means of Microsoft Visual Studio®.

How to

Tutorial videos


Note: Tutorial videos are embedded from the Phoenix Contact Technical Support YouTube channel.  With playing an embedded YouTube video in this platform, you accept the YouTube Terms & Conditions.
Depending on your personal settings in the Cookie consent dialog you may have allowed cookies for marketing purposes which will remain on your device. The data gained through this will be used by YouTube to provide video suggestions and advertisements based on your browsing habits, and may be made available to other parties. 

Step-by-step instructions

Preconditions for these instructionsShow preconditions for this instructions 

Hardware used here

  • AXC F 2152 Starterkit
  • Computer connected via Ethernet LAN

Software used here

  • Microsoft® Windows® 10
  • Internet browser
  • WinSCP
  • Microsoft® Visual Studio® 2015 and 2017
  • PLCnext Technology Development Tools for Visual Studio
  • PLCnext Engineer

Additional instructions

For further information on the debug functions in PLCnext Engineer and in Microsoft® Visual Studio®, please refer to their associated documentation.

Note: All steps in the following description are based on the default settings. Consider all changes made by the user.

Currently, the C# debugging function does not feature an interface for logging on to the controller. To debug the C# code, you have to deactivate the user authentication in the WBM on the controller (for additional information, please refer to the WBM section).


  1. Disable the user authentication

    Risk of unauthorized access

    To debug the C# code, you have to deactivate the user authentication on the controller.

    With security functions switched off, the controller must not be used for live operation.

    Make sure to switch on security functions after debugging.

    • Log in to the Web-based Management on your PLCnext Control via a browser.
    • Disable the user authentication:
      User authentication
    • Apply the changes and close the browser.
  2. Open a port and deactivate TLS
    • In WinSCP, establish a connection to the IP address of the controller with root privileges:
      establish connection
    • Open this directory: /etc/plcnext/device/System/RscGateway/
    • Open the RscGateway.settings file:
      Directory with RscGateway.settings file
    • Scroll to the line with <TcpGatewaySettings...>
    • Insert this line of code:
      <TcpGatewaySettings gatewayId="0" tcpPort="41101" sessionTimeout="300000" encrypted="false" />
      as shown here:
      RscGateway.settings insertion
    • Save and close the file
    • Restart the controller
  3. Prepare a project
  4. Activate debug mode

    Risk of personal injury or damage to equipment

    Using the debugging function can result in an unsafe process interruption.

    Ensure that there is no risk of personal injury or damage to the equipment.

    • Connect PLCnext Engineer to the controller.
    • In the PLANT area, right-click on the controller.
    • In the context menu, select Debug On/Off:
      Switch Debug On or Off
  5. Attach Visual Studio to the process
    • In Visual Studio open the DebugAttach to Process... menu.
    • From the Transport drop-down list, select the eCLR Device entry.
    • From the Connection target drop-down list, select the <Current_Controler_IP>:41101 (Last PlcNext Engineer connect) entry.
      This will take the settings of your last debug session with the PLCnext engineer and a PLCnext controller.
      If you configuration does not work or has changed recently, you can update it as following:
      • Click on the Find... button.
      • In the Attach to eCLR dialog that opens, click Load to get the settings of a recent PLCnext Engineer connection to the controller.
    • If this didn't work either, you can still set the IP address and port, as well as the path to the binary image manually: 
      • Enter the IP address of the controller and port number (e.g.,
      • Select the *.img binary image under the following path:
        C:\users\Public\Documents\PLCnext Engineer\Version\Binaries\PROJECT1@binary\eCLR\
        Debugging VS Settings
      • Choose the image currently running on the controller.
      • Confirm your selection with OK.
    • After setting the IP address and port, and the path for the binary image, click the Attach button.
    • Then add breakpoints in Visual Studio and execute the code.
    • Execution of the code will stop at the breakpoint. You can now evaluate the current variable values:
    • Use the functions in the Visual Studio toolbar to jump to the next breakpoint or continue processing of the code:
      continue after breakpoint
  6. Make changes to the code while debugging

    If you want to make changes to the code within the framework of debugging, you have to disconnect (detach) the process connection:

    • In Visual Studio, choose Debug → Detach All from the menu:
      Detach All
    • Make changes to the code and save them
    • Recompile the project; to do so, open the Build → Rebuild menu and choose your project
    • Then, switch to PLCnext Engineer
    • PLCnext Engineer will already have recognized the changes and prompts you to save the project.
      Note: If the inputs/outputs have been changed in the code, errors might occur in PLCnext Engineer. If necessary, correct them in PLCnext Engineer, too.
    • Transfer the changed project to the controller
    • Then, reconnect Visual Studio to the process (see step 5 above) and continue debugging your code
  7. Revert to secure mode

    When finished with debugging, revert the security functions before using the controller in live operation:

    • Remove or encrypt the unencrypted TCP port.
    • Enable user authentication in the WBM.




•  Web browser recommendation: Chrome/Edge 88 or newer, Firefox ESR 90 or neweror Safari • 
• Published/reviewed: 2022-09-14 • Revision 046 •