'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

Migrating database from ASP.NET Identity to ASP.NET Core Identity

Customize User's Profile in ASP.NET Identity System

Lambda two tables and three tables inner join code samples