Monday, July 20, 2009

Adventures while building a Silverlight Enterprise application part #16

So I've seen the release of Silverlight 3 coming for a while now and we've had some discussion about upgrading or not. In the end we concluded that the only reason not to upgrade would be a big impact on our existing application. We decided we would have to wait for the final release before testing it with our current code.

I've heard a lot about backwards compatibility, but I've heard that before with other upgrades and I had a lot of disappointment when actually trying that out. When it comes to backwards compatibility I guess seeing is believing. So last week I took some time to check out the upgrade to Silverlight 3.

To make sure I wouldn't do anything to my own development environment I decided to take a virtual machine and test it on that.
Here is what steps I planned to test our application with Silverlight 3:
  1. Install the Silverlight 3 Runtime
  2. Test our application with the Silverlight 3 Runtime
  3. Install a Silverlight 3 development environment
  4. Change the .aspx page to use the object tag instead of the asp:Silverlight control
  5. Get the complete solution to compile
  6. Get the application to run
  7. Test for behavior changes
The first two steps were a breeze and everything worked as expected. This was great, but I had somewhat expected this as the Silverlight 3 Runtime was still handling my application as if it was a Silverlight 2 application. Test passed.

Because all I wanted to do with the development environment was test the Silverlight 3 migration of our client software, I decided to use the new Microsoft Web Platform Installer to setup the tools needed. I haven't tried it before, so I didn't know what to expect. Actually I had only one surprise during setup, which was with the installation of IIS. It requested me to insert the disks for, in this case, Windows XP SP2, so it could copy the files for IIS from that disk.

Other than that, which is still a logical choice as IIS is obviously part of the Windows license you have, everything was downloaded and installed automatically and I was done installing everything in two hours, while reading up on breaking changes between Silverlight 2 and 3 (weird for a backwards compatible release, right :-p). All in all I was pleasently surprised by this great new solution from Microsoft and I hope they soon allow us to install your licensed version of Visual Studio trough the WPI.

Now that I was ready to test the actual upgrading of my application to Silverlight 3, I copied the sources to my virtual machine and opened the solution with Visual Web Developer. Apart from some mistakes where I forgot to copy some linked files, it opened and converted my solution without any hickup.
After putting in the missing files, it compiled without problems. I pressed F5 and waited with anticipation... worked on the first try! However, I was going a little to fast as I didn't replace the asp:Silverlight tag with the object tag and it was still running with the famous quirks mode enabled (as the minimal version still pointed to Silverlight 2). I replaced the asp:Silverlight tag with the object tag as it looks below:

<div id="silverlightControlHost">
<object data="data:application/x-silverlight-2," type="application/x-silverlight-2" width="100%" height="100%">
<param name="source" value="ClientBin/someapp.xap"/>
<param name="onerror" value="onSilverlightError" />
<param name="background" value="white" />
<param name="minRuntimeVersion" value="3.0.40624.0" />
<param name="autoUpgrade" value="true" />
<a href="" style="text-decoration: none;">
<img src="" alt="Get Microsoft Silverlight" style="border-style: none"/>
<iframe id="_sl_historyFrame" style='visibility:hidden;height:0;width:0;border:0px'></iframe>

I ran the application again...
...and it still worked as expected! After some more testing, the only change in behavior that I could find in our application was with the ListBox.ScrollIntoView method. In Silverlight 2, if you would call this with the last item in the listbox, it would scroll it into view, but it would still be at the bottom of the screen. In Silverlight 3, if you call this with the last item, it will actually scroll the item to the top of the listbox, showing empty space below it. As this is the preferred behavior in our case, I haven't done any research to see if I could change it.

All in all, this has been one of the most painless migrations I have experienced ever. Microsoft, my compliments on a job well done.


  1. Hi Jonathan,

    Because too many quality blog entries are lost in the vastness of the web, Code Project is bringing together the best to give them the exposure they deserve. Code Project has 6.3 million members browsing 23,800 articles, each article having hundreds of views daily.

    I've been looking at your blog and there are some great entries (like this one) that we'd love to have on Code Project.

    Just blog as normal on your blog page, and a version of whatever entries you choose will appear on Code Project as well with a link back to your entry on your blog.

    I'd be happy to give you the details, or answer any questions you might have.

    Sean Ewington
    Content Manager
    The Code Project

  2. Hi Sean,

    I consider that a great compliment. However, I do have some questions I would like to ask you. Is there any way I can contact you, except through my blog?