How to debug WF 4.0 designers
In WF 4.0 writing custom activities is much more exciting than it was with WF 3.5.
The combination of WF and WPF provides power and freedom to create user friendly activities. Now more then ever the designer is an important part of the activity development.
The designer is actually a WPF control, The class Microsoft.Windows.Design.Model.ModelItem provides the linkage between WF and WPF. As we all know with WPF it is easy to create amazing UI (in out case activities designers) so it is no surprise that there are many scenarios where most of the development effort is put in the designer.
The problem comes when you want to debug the designer code.
The designer code is run by Visual Studio when the WF developer uses the custom activity to create a new WF. How is it possible to stop on a break point and debug code running by Visual Studio?
Well, It is simple.
To debug designer code you need two instances of VS. One will do the debugging and the other will activate the code.
- Open one instance of VS and open the designer code.
- Put breakpoints in the designer code.
- Open another instance of VS and create a new test workflow in which you will use the new custom activity.
- Go back to the first instance of VS. Under the debug menu choose "Attach To Process" and choose the process devenv.exe (this is the second instance of VS with the test WF)
- Go back to the second instance of VS and in the test Workflow use the new activity.
- The designer code will run and it will stop on you breakpoint opening you a debug session in the first instance of VS.
Now that you know how to debug WPF designer code nothing will stop you from writing amazing designers.
Good luck
Manu