Debugging custom Data Flow Item Class Libaries

This is the fourth and final post in a series focused on Data Flow development.

Probably the most important tool used while developing software is the debugger. The debugger lets you step through your code and inspect the state of your program during runtime, so you can see what’s actually going on.

This post will focus on how to debug your custom class libraries while they are being executed by the Profitbase InVision Worker. For information on how to deploy your assembly (build and copy to target folders), you should read Part 1 of this series.

In order to debug an assembly while it’s being executed, the debugger needs to be attached to the executing process. When you start your program in debug mode from Visual Studio, this obviously happens automatically. When, however, an assembly is being executed by some other process, you need to manually attach the debugger to that process in order to be able to step through the code while it’s being executed.

To attach to the InVision Worker process from Visual Studio, go to Debug -> Attach to Process from the menu bar (or press Ctrl + Alt + P) and locate dfworker.exe from the list of processes. (You may need to enable “Show processes from all users” in order for dfworker.exe to show up). Then click Attach to attach to the selected process.

debugger_attach_dfworker

Go to your code and add a break point where you want to start debugging. Then go to your InVision Solution and start the Data Flow that executes the Data Flow Item where your code gets called. Switch back to Visual Studio and wait for your code to get called from the executing process. When your code gets called, the debugger will pause the execution of the program where you put your break point, so you’ll be able to step through your code line by line while you examine the state of your program.

Use the following keys to step through your code:

  • F10 executes the current line and continues to the next
  • F11 executes the next statement and steps into any function calls
  • F5 continues execution of the program (until the next break point if there is one)

Finding the correct process

If there are multiple instances of the Worker service, you need to identify the correct process to attach to using the (process) ID. To find the correct process ID, open a command prompt and run

tasklist /svc /fi "IMAGENAME eq dfworker.exe"

This will list all the InVision worker services on the server, displaying the PID (process ID) along with the service name.

Automatically attaching

Each time you have modified your code and rebuilt your Class Library, you need to reattach to the process in order to debug. Doing this over and over again can pretty tedious, but thankfully there’s a free Visual Studio extension available that lets you automatically reattach to a process you previously attached to. The extension is called ReAttach and can be downloaded from here. The instructions on how to use the extension is described at that site, so I won’t repeat them here.

That’s it for now on developing custom Class Libraries for Data Flows. Hopefully, someone will find it useful:) Happy coding!

-The InVision Team