title: Order of validation messages from custom attribute in MVC3 view model
body: <p>We have created the following view model in one of our MVC3 projects:</p>
  
  <pre><code>[PropertiesMustMatch("Email", "ConfirmEmail", ErrorMessage = "The email address you provided does not match the email address in the confirm email box.")]
  [PropertiesMustMatch("NewPassword", "ConfirmPassword", ErrorMessage = "The new password you provided does not match the confirmation password in the confirm password box.")]
  public class ActivationStep2ViewModel
  {
    .....
  </code></pre>
  
  <p>The PropertiesMustMatch is a custom attribute that we have created, code as below:</p>
  
  <pre><code> [AttributeUsage(AttributeTargets.Class, AllowMultiple = true, Inherited = true)]
  public class PropertiesMustMatchAttribute : ValidationAttribute
  {
      private const string _defaultErrorMessage = "'{0}' and '{1}' do not match.";
      private readonly object _typeId = new object();
  
      public PropertiesMustMatchAttribute(string originalProperty, string confirmProperty)
          : base(_defaultErrorMessage)
      {
          OriginalProperty = originalProperty;
          ConfirmProperty = confirmProperty;
      }
  
      public string ConfirmProperty { get; private set; }
      public string OriginalProperty { get; private set; }
  
      public override object TypeId
      {
          get
          {
              return _typeId;
          }
      }
  
      public override string FormatErrorMessage(string name)
      {
          return String.Format(CultureInfo.CurrentUICulture, ErrorMessageString,
              OriginalProperty, ConfirmProperty);
      }
  
      public override bool IsValid(object value)
      {            
          PropertyDescriptorCollection properties = TypeDescriptor.GetProperties(value);
          object originalValue = properties.Find(OriginalProperty, true /* ignoreCase */).GetValue(value);
          object confirmValue = properties.Find(ConfirmProperty, true /* ignoreCase */).GetValue(value);
          return Object.Equals(originalValue, confirmValue);
      }
  }
  </code></pre>
  
  <p>However, on the view, when there is a mismatch between both the 1) Email and Confirm email and 2) the password and confirm password, the validation message for the password is displayed on top. See image below:</p>
  
  <p><img src="https://i.stack.imgur.com/JWsRV.png" alt="enter image description here"></p>
  
  <p>We would like the validation message for the Email text boxes to be displayed on top as these text boxes appear before the password text boxes. </p>
  
  <p>NOTE: The order of the messages on local build (through VS2010) works as expected. The order of messages is screwed up only in our DEV and TEST environments. Looking at the deployed DLLs through reflector, this is what is displayed: (the order of attributes is reversed)</p>
  
  <p><img src="https://i.stack.imgur.com/Pn0po.png" alt="enter image description here"></p>
  
  <p>What can we do to fix this on the release builds? 
  Any help / suggestions would be much appreciated. </p>
  
  <p>Thanks.</p>