Silverlight v1.1 authoring and debugging tips for Visual Studio 2005

19 June 2007

[RAW]

As the Silverlight tools story is still young (Visual Studio 2008 really is looking amazing though), I thought I’d share a few solutions I’ve come across while working on Silverlight.

If you’re using Visual Studio 2005 for Silverlight application development (also here), these tips are for you!

Build straight into IIS folders

Depending on your personal preference for web development, you may find it handy to simply have your Silverlight class libraries build directly into your %systemdrive%\inetpub\wwwroot\projectDirectory\ folder.

If you’re also deploying ASP.NET pages, you’ll want to convert the directory into a virtual directory application also.

  1. Open your project’s Properties [Project | very bottom menu item]
  2. Click on the Build tab
  3. Within the Output group, modify the Output path to point at your virtual directory
  4. In the Debug tab, optionally also update the browser URL and/or command line arguments to point at your local web server & the virtual directory

Setup project configurations for Firefox and IE

Managed debugging works with both Firefox & Internet Explorer, and often you can track down bugs and unknown behavior by intercepting all managed exceptions from within Visual Studio.  Instead of having to attach to the Firefox.exe process with each execution, you can just add a new configuration to start it with a press of F5.

Debug tab open, Project Configuration, Visual Studio 2005

In Visual Studio 2005, you can easily add new project configurations & set the debugging parameters to save time:

  1. With the ‘Debug’ configuration selected, I’d recommend these settings for typical IE Silverlight development in VS’05:
    • Debug Start Action: Start external program “d:\program files\Internet Explorer\iexplore.exe” (adjust to point at your %systemdrive%, and if on an x64 machine, point to your 32-bit Internet Explorer installation)
    • Start Options: Command line arguments should be the URL to your local web server and the virtual directory you deploy to
    • Make sure that ‘Enable unmanaged code debugging’ is -not- checked
  2. Use the solution Configuration Manager to add/edit project configurations.  Edit the ‘Debug’ configuration to use a name such as ‘WebDebugIE’

    Configuration dropdown in Visual Studio
  3. Create a new configuration, based on WebDebugIE, and name it WebDebugFirefox.  With the new configuration selected, set the external program start path to your Firefox installation, such as “d:\program files\mozilla firefox\firefox.exe

Just select the configuration you’d like to execute your application with and debug away!

Once you’ve created one of these projects, you can use the “Export Template” wizard within the File menu to save this as a new template too.

Debug symbols and your web server

A friendly reminder that your web server should be serving PDBs in order to get anything useful out of your debugging experience.  You should probably enable serving .pdb, .xaml, and .dll files from any directories where you’re wanting to place your applications created for Silverlight.

On IIS:  Add appropriate MIME types in inetmgr.  You can use application/x-msdownload, application/xaml+xml, application/octet-steam, as long as it’s a servable type it should be good to go.

On Apache: I’m able to have xaml, pdb, and dll all served out of the box running Apache 2.2.2 on Linux, without any configuration changes or new directives.

Don’t use Scriptable objects right out of the gate

I’ve seen some people utilize the WebApplication.CreateScriptableObject method in their loaded event, and then on their JavaScript page assuming that immediately after calling CreateSilverlight() you can access Control1.content.YourScriptableObject.YourScriptableProperty.

This isn’t the case, please make sure to check whether Control1 && Control1.content are null, or use the onLoad event of the Silverlight createObjectEx method in Silverlight.js. 


Hope this helps everyone out there playing around with the Silverlight MIX CTP bits!

[/RAW]

Jeff Wilcox is a Software Engineer at Microsoft in the Open Source Programs Office (OSPO), helping Microsoft engineers use, contribute to and release open source at scale.

comments powered by Disqus