Friday, August 27, 2010

Xaml has a "Shadows" problem

If you declare a property "Shadows" (in VB terms) another property in its superclass, then Xaml loader will throw out an AmbiguousMatchException because it can not decide which one to use in this case, as a reflection operation will return multiple properties. Solution is to make the property Overridable (or virtual in C#) and overrides it.
The frustrating thing is: Despite the straight forward explanation that you have here, the debugging of this problem takes forever. There are two reasons for it:
1) AmbiguousMatchException does not tell you the offending property name and object it is raising against.
2) Microsoft Symbol Server, which supposedly should give you the source code for mscorlib, only turns out names of the method. No source code, and in turn the call parameters, are provided so there is virtually no way to find out what is wrong unless you have the knowledge and patience to go through the disassembly.
What I did ultimately is very much akin to the S&L (Save and Load) in games. I commented some code and see if the exception is raised. If not, I uncomment some. Until I found out the offending piece of code and discovered this little problem. Which is, by the way, not surprising at all. But it sure made my life miserable in the past 12 hours.

No comments: