Search code examples
asp.net-mvc-3teamcitywindows-server

CompareAttribute isn't found when building in TeamCity (on Windows Server 2012 RC)


I'm trying to build an MVC project on TeamCity installed on a server with Windows Server 2012 RC.

I'm receiving the below errors. It looks like some kind of clash with MVC versions, which is what if found when I've been googling around. I'm referenceing system.web.mvc etc explicitly by version, so I don't know what the problem is. Any ideas?

Models\AccountModels.cs(26, 10): error CS0246: The type or namespace name 'Compare' could not be found (are you missing a using directive or an assembly reference?) 
Models\AccountModels.cs(26, 10): error CS0104: 'CompareAttribute' is an ambiguous reference between 'System.ComponentModel.DataAnnotations.CompareAttribute' and 'System.Web.Mvc.CompareAttribute' 
Models\AccountModels.cs(64, 10): error CS0246: The type or namespace name 'Compare' could not be found (are you missing a using directive or an assembly reference?) 
Models\AccountModels.cs(64, 10): error CS0104: 'CompareAttribute' is an ambiguous reference between 'System.ComponentModel.DataAnnotations.CompareAttribute' and 'System.Web.Mvc.CompareAttribute' 

Solution

  • You have to explicitly specify the namespace in the Compare attribute like

    [System.Web.Mvc.Compare("NewPassword", ErrorMessage = "The new password and confirmation password do not match.")]
    

    instead of

    [Compare("NewPassword", ErrorMessage = "The new password and confirmation password do not match.")]