Tag Archives: Visual Studio

K2 blackpearl: How to debug your Default Server Event (Codes) in Visual Studio 2013

There are times when you need to write codes in your K2 workflow to provide features that is not available out-of-box. It could be a complex logic processing, sending of formatted HTML email with table contents, etc. In this article, I’m going to show you how to attach to the K2HostServer.exe process to debug your workflow.

Pre-requisite

  1. In your Visual Studio, open the Options dialog (Tools > Options).

    87-VS_Options_Menu
    Tools > Options
  2. In the Options dialog, select the debugging category and uncheck the option, “Require source files to exactly match the original version” and click OK.
    87-Remove_debug_option
    Uncheck “Require source files to exactly match the original version”

     

Attaching to the K2HostServer.exe process

  1. Deploy your K2 process, if you have not done so.
  2. Open your process in Visual Studio.
  3. Right click on your Default Server Events (Codes), select View Code, followed by Event Item to view the codes.

    87-View_code
    Default Server Event (Codes) > View Code > Event Item
  4. Add a breakpoint.

    87-break_point
    Add a break point in your codes.
  5. In the menu, select DEBUG > Attach to process…

    87-Attach_process
    DEBUG > Attach to Process…
  6. In the Attach to Process dialog, select K2HostServer.exe under Available Processes. You may need to check the “Show processes from all users” if you are not logged in as the K2 Service account.

    87-select_K2HostServer.exe
    Select K2HostServer.exe process
  7. Next, click on the Select… button.

    87-attach_select_btn
    Click on the Select… button
  8. In the Select Code type dialog, select Debug these codes types radio button and check Managed (v4.5, v4.0) and click OK.

    87-select_code_type
    Select Managed (v4.5, v4.0)
  9. Click on the Attach button and we are ready to test the workflow!
    87-Ready_to_attach
    Attach!!

    Note: Don’t worry if the symbols are not loaded after you attached to the process. It will do so when the workflow kicks off.

 

Debugging

Start your workflow running and wait for the breakpoint to hit. When it does, it is up to your debugging skills to find your problem now =)

87-debugging
Time to debug!

Just a side note, if you are running the K2 blackpearl Server service in console mode, your Console.WriteLines will appear in the console too.

87-output_in_console
Console.WriteLine shown in K2 blackpearl Server console

 

Happy Debugging!