Silverlight: Debugging in HTTP from Visual Studio (also the Downloader!)

.NET, Silverlight, Technical stuff
See comments

I had been looking for this for quite some time, and I finally found the answer (number 14 on Google with keywords “silverlight downloader debug”). Number 14 is really too low (that’s on page 2, for Pete’s sake). Hopefully this entry will be found more easily.

Problem:

When you execute a Silverlight 2.0 application in Visual Studio 2008, it gets executed in the “file:” protocol. The page’s URL starts with C:\ (or D: or E:…) or with “file:”. This has the side effect of changing the page’s permissions. And the effect is most unwanted when you use the Downloader: since cross domain and cross protocol access is not allowed by Silverlight security, you cannot use the Downloader in the “file:” protocol!!

Solution:

Thankfully, it’s not all too difficult to run the Silverlight application in HTTP protocol in Visual Studio.

(by the way, this solution is taken from http://silverlight.net/forums/t/4185.aspx, thanks to Terri Morton)

  1. Open the solution containing your Silverlight project.
  2. In the Solution explorer, right-click on the solution and select “Add / New Web Site…”.
  3. Choose “ASP.NET Web Site”, give a name and a location, and press OK.
  4. In the new web site, delete the files “Default.aspx” and “Default.aspx.cs”.
  5. Right click on the new web site, and select “Add Silverlight Link”.
  6. From the list, select your Silverlight project.
    (note: If you have referenced class libraries, they will be added automatically)
  7. Select “Yes” from the dialog asking you if you want to enable Silverlight debugging.
  8. Copy the files “TestPage.html”, “TestPage.html.js” and “Silverlight.js” from the original Silverlight project to the new web site project.
  9. Right click on the Web Site and select “Set as Startup Project”
  10. If needed, select the file “TestPage.html” in the web site, right click and select “Set as Start Page”.
  11. Press F5 in Visual Studio.
  12. If needed, click OK to the option to “Modify the web config file to enable debugging”.

Let’s hope that we will be able to debug Silverlight in HTTP from Visual Studio directly without having to resort to this workaround…

A few words of caution:

  • You can only debug Silverlight or JavaScript on the client, not both together. If you need to switch, use the Web Site Project Property Pages, Section “Start Options” and uncheck the “Debuggers / Silverlight” checkbox.
  • If you modify the file TestPage.html or TestPage.html.js, don’t forget that you now have 2 versions of these files, so you must copy the changes to keep the files consistent!
Previous entry | Next blog entry

Comments for Silverlight: Debugging in HTTP from Visual Studio (also the Downloader!)