title: ASP.NET Core custom validation error message not localized
body: <p>I want to implement localization in a custom attribute to check if the property is a valid IP address or hostname. The validation is working fine so far, but my problem is that I only get the default english error message though my local is switched to german. I am working with resource files. I do not want to implement a client side validation for this. I know there is way to implement an Adapter but correct me if I'm wrong, this is only for client side validation.</p>
  
  <p>My custom validation class:<br></p>
  
  <pre><code>public class IPAddressOrHostnameAttribute : ValidationAttribute
  {
       public IPAddressOrHostnameAttribute(string propertyName, object desiredvalue, string errorMessage)
      {
          PropertyName = propertyName;
          DesiredValue = desiredvalue;
          ErrorMessage = errorMessage;
      }
  
      private string PropertyName { get; }
      private object DesiredValue { get; }
  
      protected override ValidationResult IsValid(object value, ValidationContext context)
      {
          var instance = context.ObjectInstance;
          var type = instance.GetType();
          var propertyValue = type.GetProperty(PropertyName).GetValue(instance, null);
          if (propertyValue.ToString() == DesiredValue.ToString() &amp;&amp; value != null)
          {
              if (Regex.IsMatch(value.ToString(), AckConstants.VALIDIPADDRESSREGEX)
                  || Regex.IsMatch(value.ToString(), AckConstants.VALIDHOSTNAMEREGEX))
              {
                  return ValidationResult.Success;
              }
  
              return new ValidationResult(ErrorMessage);
          }
  
          return ValidationResult.Success;
      }
  }
  </code></pre>
  
  <p>My model class:<br></p>
  
  <pre><code>  [Required(ErrorMessage = "The field {0} is required")]
          [RegularExpression(@"^\S*$", ErrorMessage = "No white spaces allowed.")]
          [IPAddressOrHostname(nameof(IsFileAdapter), true, "Please enter a valid IP address or hostname")]
          [IPAddress(nameof(IsFileAdapter), false, "Please enter a valid IP address")]
          [Display(Name = "Destination")]
          public string Destination { get; set; }
  </code></pre>
  
  <p>My startup class to configure the <code>DataAnnotationLocalizerProvider</code>:<br></p>
  
  <pre><code>services
                  .AddMvc()
                  .AddViewLocalization(LanguageViewLocationExpanderFormat.Suffix,
                      opts =&gt; { opts.ResourcesPath = "Resources"; })
                  .AddDataAnnotationsLocalization(options =&gt;
                  {
                      options.DataAnnotationLocalizerProvider = (type, factory) =&gt;
                          factory.Create(typeof(SharedResource)); // SharedResource is the class where the DataAnnotations (translations) will be stored.
                  })
  </code></pre>
  
  <p>The localization is working for the default attributes like e.g. <code>Required</code> etc. but not for my custom validation attribute. I have no idea what's wrong in my code. I have read the stackoverflow post <a href="https://stackoverflow.com/questions/42784311/asp-net-core-custom-validation-attribute-localization">ASP.NET Core custom validation attribute localization</a>, but I do not understand why my server side validation with localization is not working. Hopefully someone can help me or give me an example how to get it work, because this problem is driving me crazy.</p>