Migrating from Silverlight 2 Beta 2 to RTM – some issues
If you have Silverlight 2 Beta 2 apps and you want to migrate them to RTM, some things may be not-so-easy. I gathered some tips on how to deal with some of the breaking changes. Please check Nuno Godinho’s post on how to install Silverlight 2 RTM and for some great tutorials on building Silverlight apps. Also check his post on RC0 for very helpful migration guidelines.
1. Microsoft Expression Blend SP1 cannot open Silverlight 2 RTM projects
After installing Blend SP1, I still wasn’t able to open any Silverlight 2 RTM projects. Hmmmm… Wasn’t that what SP1 was for?! The trick is to run the SP1 installer from the browser (don’t save it to disk). Some people on silverlight.net forums were having the same problem, and this worked for us.
2. Opening files with File.Open
Opening files on the client with File.Open is no longer supported, for security reasons. The correct way to do it is to use OpenFileDialog’s File property. Also, this property replaces the previous SelectedFile poperty in OpenFileDialog.
Before:
OpenFileDialog dlg = new OpenFileDialog(); using(Stream s = File.OpenRead(dlg.SelectedFile.Name) { … }
Now:
OpenFileDialog dlg = new OpenFileDialog(); using(Stream s = dlg.File.OpenRead()) { … }
3. Breaking Change #2. ContentPresenter: ContentPresenter now derives from FrameworkElement instead of Control.
Probably one of the hardest changes to deal with. Many of ContentPresenter’s properties were removed (fonts, colors, alignments, etc…). In many cases, you’ll have to rethink your control tree, but sometimes you may get away with replacing ContentPresenter with a TextBlock or wrapping it in a Border. There is no fits-all solution. In a recent application, I found that in most of the places, replacing it with a TextBlock did the trick. This is the change that I’ve seen more people banging their heads with (I’ve been there and was painful!). In some scenarios, you can also get away with moving some style-related things to the container.
One final word, the final version of Silverlight 2 is a lot less forgiving than Beta 2. Make sure you don’t reference missing media or set invalid properties. You’ll know it at runtime, but most of the times, the runtime engine won’t show the origin of the error (just some message like “Invalid property: Foreground”).
Some additional recommended readings if you’re having trouble:
http://weblogs.asp.net/cschittko/archive/2008/10/12/resolving-errors-moving-to-silverlight2-rtw.aspx
http://blogs.msdn.com/expression/archive/2008/06/19/debugging-design-time-exceptions.aspx
Hope this helps.
autor: ricardo.fiel