It’s trickier than you thought, but it isn’t that bad
When you edit a copy of an Expression Encoder 3 template in Visual Studio 2008 SP1 – sometimes after you make changes they don’t always work as you expected the first time. So you have to debug. However debugging an EE3 Media Player template isn’t as easy as pressing “F5” is Visual Studio – at least when you are trying to use SmoothStreaming content.
With smooth streaming it is more complex. The main reason for this is that the Smooth Streaming content is downloaded from the web server to the client using the HTTP: protocol. However when you launch the template from within Visual Studio 2008 – the website is launched using the FILE: protocol and as a result the HTTP: protocol isn’t available to deliver packets to the client.
There are several ways to solve this problem and debug effectively. In this post I will outline one approach that has worked for me.
1) Setup a test web server. Install Windows Server 2008 and enable IIS7 and install the latest release of the IIS Media PlugIn. I recycled a several year old development machine for this – it doesn’t need much capacity – since the number of users will be small. To facilitate dropping new content and new builds of the .XAPs onto the server I usually enable file sharing and share out the WWWROOT of the website.
2) Use Expression Encoder 3 to encode some Smooth Streaming test content – be sure to select a template – hopefully the one you want to debug. Once the encoding process is complete copy the entire contents of the output to a new folder under the WWWROOT. I recommend that you uncheck the “Load Content Automatically” and “Play content automatically” checkboxes in Expression Encoder – this will make debugging easier. (more on this later)
3) Start Visual Studio 2008 and load the Template.SLN file for the template you are trying to debug.
4) Launch Internet Explorer and type in the URL for the webpage just created.
5) In VS2008 use the Debug->Attach To Process command – 1st change the “Attach To” setting to “Silverlight” or “Silverlight Code”. 2nd find the right process to connect to – this is a bit tricky since IE8 creates two processes – one for IE and one for the webpage. The one you want will have a blank title and say “Silverlight, x86” under the Type column.
6) Once you attached – set a breakpoint near the suspected bit of code.
7) If the code you are trying to debug is related to initialization – “unchecking” the “autoplay” check boxes about will help – refreshing the page in IE8 will restart the player – but leave the debug session intact.
8) If you are one of the few that need to debugging the code in SmoothStreaming.XAP – the break points will not be active until SmoothStreaming.XAP has be downloaded and merged into the process.
9) Once you identify a problem you’ll need to disconnect the debug session, exit IE and then fix the code and rebuilt the affected .XAP . I usually just drag the new .XAP to the webpage folder using Explorer (keeping two explorer windows open) If I’ve got a lot of work – sometimes I will add post-build step to copy the new XAP(s) to the test server share.