AmbiguousMatchException Error on Silverlight 4 RC

On March 17, 2010, in Programming, by Akash Kava

Here is quick update for the following error,

System.Windows.Markup.XamlParseException occurred
  Message=System.Reflection.AmbiguousMatchException: Ambiguous match found.

That may start popping up after you install Silverlight 4 RC or later version and its quite annoying when Silverlight does not offer any detail about the error. One of the most annoying factor in silverlight is, for every parse exception Line Number and Line Position are always zero.

I started analyzing my code and try to understand what went wrong, it took half an hour to figure out the root cause. And following is the result,

I had a derived TextBox class of silverlight and had a property named “Watermark”, however I did compile everything against Silverlight 3 only, but over curiosity I had installed Silverlight 4 RC, which has TextBox with a property named “Watermark” with type as object.

No Side by Side in Silverlight

That is bad news, because if tomorrow there is one update by Microsoft, and you are away from your desk, all of sudden support calls will start piling up. Because the new update will have few things that will raise all unexpected errors without warnings. So if you have Silverlight 3 app, if you dont plan to upgrade to 4, Silverlight will not run side by side and it will cause problems. So you will always have to keep on upgrading Silverlight apps!!

AmbigiousMatchException

This occurs when you have a property in your class as well as in the base class (usually we always will be careful to avoid this) with different type. However I dont know what exactly will happen if you have property with same type and name in base as well as child class, but it looks to me as if this is just a parse exception. Silverlight may load values correctly.

Solution

I know this is what you are looking for, but it isnt easy, what you have to find out is, if any of your class has any property whose name exactly matches with name of property defined in its base class and higher in inheritance chain. If you have same name but different type, this error will occur, it may also occur if you have property written with new keyword. It will not occur on inherited property.

Please also have a look at upcoming, rapid business form development on  WPF as well as Silverlight. Please click here to check the preview.

Share

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>