Sometimes people have difficulties to debug Silverlight applications. Let me give you a hint to make it easy. The key thing is to understand that there are two applications (processes) you might want to debug – server and client. If you typically hit F5 sometimes only server gets debugged. That’s why I do it another way.
How To Start Debugging?
- At the beginning, Start Without Debugging:
This will run the server and open the client in your default browser. Because of easier finding of the right process, I close the browser and open client URL in Internet Explorer, since I don’t use it for other tasks (you will see in a minute). You don’t have to start it again as long as the ASP.NET Development Server is running.
- Then, before you want to debug your application, you just need to build the solution (in larger applications, rebuilding of the affected project should be enough).
- Attach to Process (or press CTRL+ALT+P)
- If you want to debug server, attach to process called WebDev.WebServer40.EXE (press keys w,e,b and the listbox will find it for you):
If you want to debug client, attach to process of your browser (make sure to choose the process of Type Silverlight!). In my case, it is iexplore.exe:
So, if you want to debug your client app opened in the only Internet Explorer instance running, press: CTRL+ALT+P, i, e, ENTER. Just don’t forget to build the solution and refresh your browser (so that the latest version of client gets loaded).
- If you would like to change Default Browser of your Silverlight application, then you may do the following steps:
- It will open window "Browse With" with list of all installed browsers in your system. You may set any one to your default or favorites browser for this application.
In my case, "Firefox (Default)" was default brwoser, now I like "Internet Explorer". Select Browser from list > click on Set as Default button.
- Set a Breakpoint
In a source window, click a line of executable code where you want to set a breakpoint.
On the Standard Toolbar menu, click on Start Debugging or Press F5 to run the application.
- Start or run application
- Active or Highlight Debugger
After debugger hits the breakpoint, you may need to execute the code line by line. "Step Over" [ F10 ] command is used to execute the code line by line, when you are debugging inside a method. If you press "Step Into [F11]" within the current method, then the execution will complete the execution of the method and will pause at the next statement from where it called.
This article basically covers fundamentals of debugging in Silverlight application. It describes how to debug an application using Visual Studio.
Comments or Suggestions
If you find some issues or bugs with it, just leave a comment or drop me an email. If you make any notes on this, let me know that too so I don't have to redo any of your hard work.
Please provide a "Vote" if this would be helpful.