Tuesday, November 6, 2012

How To Debug K2 Process


K2 executes workflows on a process named K2HostServer.exe. By attaching Visual Studio or K2 Designer for Visual Studio to this process, you're able to debug and step through any code as it executes. This includes your own code and the code K2 generates. And you can even debug workflows running on production servers.
Here are step-by-step instructions for debugging your own server events. Afterwards, we'll discuss how to debug code generated by K2.

Debugging a process running on a local machine.

  1. Set a breakpoint on the code you want to debug.
    • Open the workflow inside Visual Studio or K2 Designer for Visual Studio.
    • Right-click on the server event (code) you want to debug and then click View Code -> Event Item.
    • Set a breakpoint on the code you want to debug.
  2. Attach the debugger to the K2 service.
    • Click on the Debug menu -> Attach to Process (or press Ctrl+Alt+P)
    • Tick the Show processes from all users option if it is not already ticked.
    • Select K2HostServer.exe in the list of processes and click Attach.
  3. Once a process instance reaches the server event (code) task, the breakpoint should be triggered and you will be able to debug to your hearts content.

Debugging a process running on another machine.

The steps are very similar to debugging a local machine except that you need to connect to the other machine instead of yours.
  1. Run the Visual Studio Remote Debugger on the other machine and take note of the whole server name.
    • If Visual Studio is installed, click Start -> All Programs -> Visual Studio -> Visual Studio Remote Tools -> Visual Studio Remote Debugger
    • If not installed, you can copy the file (msvsmon.exe) from your machine to the other machine. No other files are required.
    • The server name is specified in the description in single quotes.
  2. When in the Attach to Process dialog, enter the server name into the Qualifier box and press Refresh.
  3. The processes of the other machine will be listed and you will be able to select K2HostServer.exe.

Debugging code generated by K2.

Instead of placing a breakpoint on your own code, you can place breakpoints on the code generated by K2.
  1. Right-click on any workflow item, such as a mail event or activity preceding rule, and click View Code and then the applicable event.
    • If the underling workflow is displayed, right-click on an item and select View Code
  2. Place a breakpoint a code you'd like to debug and attach the debugger. Once a process reaches the code, the debugger will break/pause and you'll be able to debug the K2 generated code.

1 comment: