Ask your technical questions on forums or here :
ASP.NET or MVC | C# | Windows Phone
Microsoft Technology Journals by Abhimanyu K Vatsa
HOME ABOUT RAZOR BOOK SPEAKING MVC ASP.NET JQUERY VIDEOS ARCHIVE CONTACT

6 May 2015

'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.

Comment using Google Services (2 comments):