Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles
(untagged)

Silverlight Debugging - Beginner's Guide

0.00/5 (No votes)
22 Dec 2011 1  
Debug or attach the debugger to any local process running a Silverlight-based application in all supported browsers in your system.

Introduction

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?

  1. At the beginning, Start Without Debugging:

    1.png

    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.

  2. 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).
  3. Attach to Process (or press CTRL+ALT+P)

    2.png

  4. 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):

    3.png

    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:

    4.png

    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).

    1. If you would like to change Default Browser of your Silverlight application, then you may do the following steps:

      5.png

    2. 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.

      6.png

      In my case, "Firefox (Default)" was default brwoser, now I like "Internet Explorer". Select Browser from list > click on Set as Default button.

  5. Set a Breakpoint

    In a source window, click a line of executable code where you want to set a breakpoint.

    7.png

    On the Standard Toolbar menu, click on Start Debugging or Press F5 to run the application.

    1. Start or run application

      8.png

    2. 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.

      9.png

Summary

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.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here