Tater Salad

You can chop em up, mash em up, or boil em in a stew.

Archive for November, 2007

Debugging Silverlight 1.1 Alpha Refresh in Visual Studio

Posted by caseyrayl on November 26, 2007

I have gotten back into some Silverlight code and have been playing with the new version of Visual Studio 2008 and the Silverlight 1.1 alpha refresh. Since picking it back up I have run into some interesting speed bumps that were not there my first time around.

The 1.1 alpha refresh introduced a stricter Silverlight security model which completely disables access to any asset on the local file system. This means if your app utilizes external resources, you have to debug it via a web project of some sort. I was already using an IIS project for deployment so switching over wasn’t a big deal for me, but I had to go through some rigmarole to get it set up initially. For ASP web developers, it is probably all old hat, but for someone with no prior experience, it is an annoyance to have to set it up just so you can debug a Silverlight application. Plus you have to be running certain versions of Windows. Overall not a very friendly way to get your feet wet with Silverlight.

So what is the answer? Well there is an internal web server built into Visual Studio called Cassini. Using it and VS you can quickly create a web project that you can then link to your Silverlight application and test locally.

The process goes like this: right click on your solution that houses your Silverlight application and select Add -> New Website. In the dialog box that appears, select ASP.NET web site as the template, make sure the Location combobox is set to “File System”, and enter the path you would like the site created in. Once the project for the site is created, right click on it and select Add Silverlight Link. A dialog should appear that lists your Silverlight projects within the same solution. Click on the one you want linked in. If it asks you if you want to enable Silverlight debugging, say YES! You should now see the files for your application that are set with a build action copied into your web application. All that remains is to right click on your start page and select Set As Start Page. You should now be able to launch your Silverlight application locally and do anything you need to for testing.

If for some reason you find that the debugger isn’t loading your symbols for your application, or inexplicably skips over your break points, check that the debugging properties are correctly configured. Right click on the web project and select Property Pages. In the dialog box, select Start Options on the left side. At the bottom you will see the debuggers that are enabled for your project. If Silverlight is already checked and you still can’t debug it properly, try enabling Native Code as well. I have run into several instances where I have had to do this to get the debugger working.

-Casey

Advertisements

Posted in Uncategorized | Leave a Comment »