Friday, July 12, 2013

Error after upgrading an MVC 4 project to .NET 4.5

After upgrading an ASP.NET MVC 4 project to .NET 4.5, I was welcomed with the following error message in my output window:

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



And it are the following lines that are causing the issue:


It seems that the CompareAttribute in .NET 4.5 has been added to the list of core data annotations making it available in both the System.Web.Mvc and System.ComponentModel.DataAnnotations namespace.

Fix the problem by removing the reference to System.Web.Mvc from your class file (by deleting‘using System.Web.Mvc’ line).

No comments: