title: ASP.NET MVC - "Validation type names must be unique."
body: <p>I use ASP.NET MVC 3 and Data Annotations in my model, and want to retrieve the Error Messages from a database. So I wrote inherited attributes:</p>
  
  <pre><code>public class LocalizedRequiredAttribute : RequiredAttribute
  {
      public LocalizedRequiredAttribute(){}
  
      public override string FormatErrorMessage(string name)
      {
          return GetByKeyHelper.GetByKey(this.ErrorMessage);
      }       
  }
  
  public class LocalizedRegularExpressionAttribute : RegularExpressionAttribute
  {
      public LocalizedRegularExpressionAttribute(string pattern) : base(pattern){}
  
      public override string FormatErrorMessage(string name)
      {
          return GetByKeyHelper.GetByKey(this.ErrorMessage);
      }       
  }
  </code></pre>
  
  <p>I wrote 2 "adapters" for these attributes to enable client validations, such as this:</p>
  
  <pre><code>public class LocalizedRequiredAttributeAdapter : DataAnnotationsModelValidator&lt;LocalizedRequiredAttribute&gt;
  {
      public LocalizedRequiredAttributeAdapter(ModelMetadata metadata, ControllerContext context, LocalizedRequiredAttribute attribute)
          : base(metadata, context, attribute)
      {
      }
  
      public static void SelfRegister()
      {
          DataAnnotationsModelValidatorProvider.RegisterAdapter(typeof(LocalizedRequiredAttribute), typeof(RequiredAttributeAdapter));
      }
  
      public override IEnumerable&lt;ModelClientValidationRule&gt; GetClientValidationRules()
      {
          return new[] { new ModelClientValidationRequiredRule(ErrorMessage) };
      }
  }
  </code></pre>
  
  <p>And in my global.asax I have these 2 lines:</p>
  
  <pre><code>        LocalizedRegularExpressionAttributeAdapter.SelfRegister();
          LocalizedRequiredAttributeAdapter.SelfRegister();
  </code></pre>
  
  <p>I get an exception "Validation type names in unobtrusive client validation rules must be unique. The following validation type was seen more than once: required" when my model renders the HTML for this property:</p>
  
  <pre><code>    [LocalizedRequired(ErrorMessage = "global_Required_AccountName")]
      [LocalizedRegularExpression(User.ADAccountMask, ErrorMessage = "global_Regex_AccountName")]        
      public string AccountName { get; set; }
  </code></pre>
  
  <p>What is wrong?</p>