Debugging an application helps in finding and reducing bugs. While debugging a Silverlight application in Visual Studio, one might think, all that it takes to debug a SL application is to set a breakpoint in your code and run the application in Debug mode. However that’s not true and you will find that the debugger never breaks at the breakpoint.
In order to debug a Silverlight application, you have to attach to a running instance of the application in your browser. Let us see how to do this:
Open Visual Studio 2008/2010 and set a breakpoint in your code. Now run the application. In Visual Studio, Go to Tools > Attach to Process
You will see multiple instances of the browser in which you are running the Silverlight application. I am running the Silverlight application on Chrome, so I see multiple instances of Chrome as shown below:
Out of all these instances, you have to choose the process that has the Type ‘Silverlight’ and hit the ‘Attach’ button.
Note: Although the debugger automatically detects and attaches itself to the right type of process, make sure that ‘Attach To’ box is set to Silverlight Code as shown in the screenshot above (circled)
That’s it. Now when you hit a breakpoint, you will be able to debug your code.