Resolving Errors - Moving to Silverlight2 RTW

Following Jesse’s and Pete’s excellent posts on porting Silverlight2 apps from Beta 2 to the final release bits I thought I add just a little more information.

As I worked with one of my customers that’s featured in the launch press release through their code, I thought it would be nice to understand the error you’re getting as you port.

1. The new app type. This is a well documented first step you need to take to see more than the “download silverlight” badge.

image

The fix is easy. Change the <object> tag from
 
<object data="data:application/x-silverlight," type="application/x-silverlight-2-b2" …>

to

<object data="data:application/x-silverlight-2," type="application/x-silverlight-2" … >

2. Fix your references to the vsm namespace (xmlns:vsm="clr-namespace:System.Windows;assembly=System.Windows")

Those result in XamlParseException with error code AG_E_RUNTIME_MANAGED_UNKNOWN_ERROR. Curiously enough those exceptions occur on the LoadComponent call that’s loading and parsing Xaml from the .xap (as explained by Shawn), but the exception details don’t give you much details what you need to get rid of them. For example, your code may reference the vsm namespace in the Application.Resources element in the App.xaml:

<vsm:Application.Resources>

If that’s the case,  the exception will occur when parsing the first child of <vsm:Application.Resources>. In my case, that was the line with the closing tag of a ContentPresenter (which has other issues (see below)). Unfortunately, that inconsistency is not caught by the Xaml validator in Visual Studio. Simply changing the Application.Resources element to:

<Application.Resources>

will get rid of this exception.

3. The next class of errors is another XamlParseException with the error code: AG_E_PARSER_PROPERTY_NOT_FOUND.

The culprit is again the namespace reference to the System.Windows namespace, often referenced with the vsm prefix. Again, you will see this exception not on the element that’s actually causing the problem. In my case it was again </ContentPresenter>.

Search and Replace of vsm:Setter and vsm:Setter.Value with the “Entire Solution” option gets rid of these errors pretty quickly. While you’re at it, replace vsm:Style with Style.

image

4. ScrollViewer and other ContentControl derived classes no longer have Text* properties.

You’ll get validation errors when the parameters are set explicitly in code, but you get a XamlParseException: Invalid attribute value TextAlignment for property Property.

when you define a Style that would set TextAlignment and TextWrapping properties.

<Style x:Key="RightScrollbarScrollerTemplate" TargetType="ScrollViewer">
    <Setter Property="TextAlignment" Value="Left"/>
    <Setter Property="TextWrapping" Value="NoWrap"/>

Those properties were removed for compatibility with WPF. You now have to make sure that the ContentControl’s container sets Text* properties correctly – either explicitly or via <Style>

5. ContentPresenter no longer derives from Control, thus it’s missing a number of properties that could be set in code or in XAML.

Jesse posted about solving these issues at length. The good news is that you can catch this issue at design time through Visual Studio warnings:

The property 'Foreground' does not exist on the type 'ContentPresenter' in the XML namespace 'http://schemas.microsoft.com/winfx/2006/xaml/presentation'

and at run time with XamlParseExceptions when launching the app: XamlParseException: Unknown attribute Foreground on element ContentPresenter.

6. The name of the Duration property on Visual Transition changed to GeneratedDuration.effects you’ll see are:

Compiler errors:

The property 'Duration' was not found in type 'VisualTransition'.   

and Validation warnings:

The property 'Duration' does not exist on the type 'VisualTransition' in the XML namespace 'clr-namespace:System.Windows;assembly=System.Windows'.   

Follow Jesse’s instructions to fix it.

 

For other issues check the breaking changes documentation or start with Mike’s post

1 Comment

  • i get an error (the Install Silverlight graphic) when i click your

    Innovation - Explore the Interactive Deck from TechEd 2008

    of course it's probably Silverlight.Services.live.com

Comments have been disabled for this content.