'CompareAttribute' is an ambiguous reference between 'System.ComponentModel.DataAnnotations.CompareAttribute' and 'System.Web.Mvc.CompareAttribute'

'CompareAttribute' is an ambiguous reference between 'System.ComponentModel.DataAnnotations.CompareAttribute' and 'System.Web.Mvc.CompareAttribute'

As in error message, CompareAttribute is ambiguous means this method is somehow present twice on the page. Here is the error screenshot:


If you read MSDN documentation you will find System.Web.Mvc as well as System.ComponentModel.DataAnnotations both contains the definition for CompareAttribute.

Here is the image, notice that System.Web.Mvc's CompareAttribute is now marked as Absolute (aka not supported) with the release of .NET 4.5.


How to resolve?

Now to fix this, all you need is remove ‘System.Web.Mvc’ from your class file and issue will go away.

Hope this helps.

Comments

Post a Comment

Popular posts from this blog

5 Ways to send data between ASP.NET Pages