Debug Silverlight Applications in Visual Studio

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

image

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:

image

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.

image






About The Author

Suprotim Agarwal
Suprotim Agarwal, Developer Technologies MVP (Microsoft Most Valuable Professional) is the founder and contributor for DevCurry, DotNetCurry and SQLServerCurry. He is the Chief Editor of a Developer Magazine called DNC Magazine. He has also authored two Books - 51 Recipes using jQuery with ASP.NET Controls. and The Absolutely Awesome jQuery CookBook.

Follow him on twitter @suprotimagarwal.

1 comment:

Anonymous said...

I think you don't have to do this if you're working with IE.