Tuesday, February 3, 2009

Error Messages in Silverlight

Can you guess what’s wrong with this Xaml code, on the first look?

<Application xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
x:Class="Test.UI.App"
>
<
Application.Resources>

<
Color x:Key="HeaderRectangleStrokeColor">#FF777676</Color>
<
Color x:Key="AppInvertTitleForegroundColor">#16FFFFFF</Color>
<
Color x:Key="AppTitleForegroundColor">FFFFF8F8</Color>
<
Color x:Key="PageBackground">#FF000000</Color>

<
SolidColorBrush x:Key="HeaderRectangleStrokeBrush" Color="{StaticResource HeaderRectangleStrokeColor}" />
<
SolidColorBrush x:Key="AppInvertTitleForegroundBrush" Color="{StaticResource AppInvertTitleForegroundColor}" />
<
SolidColorBrush x:Key="AppTitleForegroundBrush" Color="{StaticResource AppTitleForegroundColor}" />

<
LinearGradientBrush x:Key="HeaderRectangleBrush" EndPoint="0.5,1.011" StartPoint="0.5,-0.011">
<
GradientStop Color="#FF343333" Offset="0"/>
<
GradientStop Color="#FF3E3E3E" Offset="1"/>
</
LinearGradientBrush>

</
Application.Resources>
</
Application>

Application compiles just fine. Even Resharper can not detect a problem in it. But when you running it a hard error happens that fails the Silverlight plug-in! What’s worse, is that the error message is cryptic as can be :
Silverlight-TestPage-Error

My Application resource had more Colors and Brushes than the example here, so it was much harder to find the needle in haystack. Luckily I found out what the problem was. The Color value for one of the resource has missing # mark. Shouldn’t there be a more explicit error message?


Submit this story to DotNetKicks Shout it

No comments: