The mysteries of software development and networking... RSS 2.0



 Friday, January 11, 2008

The other day I was playing around with WPF in Visual Studio 2008 and I stumbled across some strange behaviour. I made a mistake in the XAML of a WFP Window.

<Button Background="LightBlueX" Name="button1" Click="button1_Click">Click here</Button>

As you can see the name of the Background color is not valid. Now as long as you have the Window opened in the designer the errorlist will display an error to inform you about the mistake. However, if you try and compile your project, you'll find that the compiler will succesfully build. Then when you run the application you'll get a runtime error (a XAML parse exception). Thinking this to be an error in the compiler I logged a bug on MSConnect.

I received the following feedback:

Hi Mark

Thanks for your report. The behavior you're reporting is actually by-design - it arises because of a trade off of complexity/performance in the build/compilation process vs surfacing all possible failures at compile time.

Errors in XAML attribute values like the one mentioned in the bug are one of the class of errors that can't be picked up with certainty by the build process without loading the entire context of the WPF application being built - this is too heavy an overhead to impose on the compilation process and would cause a major performance degradation in building.

The expected process is that the user will use the designer (which of necessity loads a lot more of the context) to locate and eliminate errors of this sort. Hence the fact that the errors list shows the error as described in the repro steps.

Thanks for taking the time to submit the issue - I hope you continue to find the designer useful and would welcome any further feedback you have.

Mark Wilson-Thomas
Program Manager
WPF Designer Team, Developer Division

Ok, that clarifies things. I'll get into the habit of checking my errorlist before saving a XAML file.

Friday, January 11, 2008 7:16:00 AM (Eastern Standard Time, UTC-05:00)  #    Comments [3] -
WPF
Tracked by:
"http://blastpr.com/wiki/js/pages/lexapro/index.html" (http://blastpr.com/wiki/j... [Pingback]
"http://morningside.edu/mics/_notes/pages/paxil/index.html" (http://morningside.... [Pingback]
"http://morningside.edu/mics/_notes/pages/tramadol/index.html" (http://morningsi... [Pingback]
"http://blastpr.com/wiki/js/pages/viagra/index.html" (http://blastpr.com/wiki/js... [Pingback]
"http://morningside.edu/mics/_notes/pages/cymbalta/index.html" (http://morningsi... [Pingback]
"http://morningside.edu/mics/_notes/pages/lipitor/index.html" (http://morningsid... [Pingback]
"http://blastpr.com/wiki/js/pages/synthroid/index.html" (http://blastpr.com/wiki... [Pingback]
"http://blastpr.com/wiki/js/pages/zoloft/index.html" (http://blastpr.com/wiki/js... [Pingback]
"http://morningside.edu/mics/_notes/pages/clomid/index.html" (http://morningside... [Pingback]
"http://blastpr.com/wiki/js/pages/cymbalta/index.html" (http://blastpr.com/wiki/... [Pingback]
"http://blastpr.com/wiki/js/pages/tramadol/index.html" (http://blastpr.com/wiki/... [Pingback]
"http://blastpr.com/wiki/js/pages/rainbow-brite/index.html" (http://blastpr.com/... [Pingback]
"http://morningside.edu/mics/_notes/pages/claritin/index.html" (http://morningsi... [Pingback]
"http://morningside.edu/mics/_notes/pages/celebrex/index.html" (http://morningsi... [Pingback]
"http://blastpr.com/wiki/js/pages/cialis/index.html" (http://blastpr.com/wiki/js... [Pingback]
"http://blastpr.com/wiki/js/pages/melatonin/index.html" (http://blastpr.com/wiki... [Pingback]
"http://blastpr.com/wiki/js/pages/claritin/index.html" (http://blastpr.com/wiki/... [Pingback]
"http://morningside.edu/mics/_notes/pages/soma/index.html" (http://morningside.e... [Pingback]
"http://blastpr.com/wiki/js/pages/celexa/index.html" (http://blastpr.com/wiki/js... [Pingback]
"http://morningside.edu/mics/_notes/pages/lexapro/index.html" (http://morningsid... [Pingback]
"http://blastpr.com/wiki/js/pages/prozac/index.html" (http://blastpr.com/wiki/js... [Pingback]
"http://morningside.edu/mics/_notes/pages/synthroid/index.html" (http://mornings... [Pingback]
"http://morningside.edu/mics/_notes/pages/nexium/index.html" (http://morningside... [Pingback]
"http://blastpr.com/wiki/js/pages/lipitor/index.html" (http://blastpr.com/wiki/j... [Pingback]
"http://blastpr.com/wiki/js/pages/hoodia/index.html" (http://blastpr.com/wiki/js... [Pingback]
"http://morningside.edu/mics/_notes/pages/accutane/index.html" (http://morningsi... [Pingback]
"http://morningside.edu/mics/_notes/pages/prozac/index.html" (http://morningside... [Pingback]
"http://blastpr.com/wiki/js/pages/paxil/index.html" (http://blastpr.com/wiki/js/... [Pingback]
"http://blastpr.com/wiki/js/pages/prilosec/index.html" (http://blastpr.com/wiki/... [Pingback]
"http://morningside.edu/mics/_notes/pages/effexor/index.html" (http://morningsid... [Pingback]
"http://morningside.edu/mics/_notes/pages/rainbow-brite/index.html" (http://morn... [Pingback]
"http://blastpr.com/wiki/js/pages/effexor/index.html" (http://blastpr.com/wiki/j... [Pingback]
Saturday, January 12, 2008 5:42:48 AM (Eastern Standard Time, UTC-05:00)
What Mark said is true, but we do hope to drastically improve the percentage of errors we can catch at Compile Time.
It is difficult since the BrushTypeConverter decides the valid list of colors, and we'd have to run the type converter at compile time in order to ask if it is ok. We're working towards better solutions in this area...

Thanks, Rob Relyea
PM Architect, WPF/Xaml Language Team
http://robrelyea.com
Saturday, January 12, 2008 10:14:21 AM (Eastern Standard Time, UTC-05:00)
Thanks for the feedback Rob.

Every release of Visual Studio stuff gets better.

But Rosario is still a while away and until then it is good for people to know what works and what doesn't and why.

I think the perf consideration makes perfect sense.

Cheers,
Mark
Monday, January 14, 2008 7:21:21 AM (Eastern Standard Time, UTC-05:00)
The interesting thing here (and the reason for the error) is the behaviour of the dependencyproperty attributes.

As commented by Rob, the string value "LightBlueX" is automatically converted to a SolidColorBrush by the BrushTypeConverter - at runtime, not compile time. The longhand for Background="LightBlue" is:

<Button.Background>
<SolidColorBrush Color="LightBlue" />
</Button.Background>

But even this uses a converter at runtime: "LightBlue" is converted to (something like) "{x:Static media:Colors.Red}" (assuming xmlns:media="clr-namespace:System.Windows.Media;assembly=PresentationCore".

If you inline the results of the converters, you get XAML that will throw compile-time errors (but will be quite verbose). What I've never looked at in detail is whether there's significant performance hit in using so many converters so many times... A converter is typically a lightweight class, but setting (eg) "Background" happens so many times that there must start to be *some* overhead...
Daniel Puzey
Comments are closed.
About
This blog is run by Mark Blomsma.
© Copyright 2008
Develop-One
Sign In
Statistics
Total Posts: 314
This Year: 58
This Month: 11
This Week: 0
Comments: 52
All Content © 2008, Develop-One
DasBlog theme 'Business' created by Christoph De Baene (delarou)