title: DataAnnotations localization in asp net core 2
body: <p>I'm trying to implement this: <a href="https://docs.microsoft.com/en-us/aspnet/core/fundamentals/localization?view=aspnetcore-2.1#dataannotations-localization" rel="noreferrer">https://docs.microsoft.com/en-us/aspnet/core/fundamentals/localization?view=aspnetcore-2.1#dataannotations-localization</a></p>
  
  <p>My code:</p>
  
  <p>Startup.cs</p>
  
  <pre><code>public void ConfigureServices(IServiceCollection services)
  {
  ...
  services.AddLocalization(options =&gt; options.ResourcesPath = "Resources");
  services.AddMvc()
      .AddViewLocalization(LanguageViewLocationExpanderFormat.Suffix)
      .AddDataAnnotationsLocalization(options =&gt;
      {
          options.DataAnnotationLocalizerProvider = (type, factory) =&gt;
              factory.Create(typeof(SharedResource));
      });
  ...
  }
  </code></pre>
  
  <p>SharedResource.cs</p>
  
  <pre><code>namespace MyProj.Classes
  {
      /// &lt;summary&gt;
      /// Dummy class to group shared resources
      /// &lt;/summary&gt;
      public class SharedResource
      {
  
      }
  }
  </code></pre>
  
  <p>FooViewModel.cs</p>
  
  <pre><code>public class FooViewModel
  {
      [Required(ErrorMessage = "EmailRequired")]
      [EmailAddress(ErrorMessage = "EmailIsNotValid")]
      [Display(Name = "Email")]
      [DataType(DataType.EmailAddress)]
      public string Email { get; set; }
  }
  </code></pre>
  
  <p>FooPage.cshtml</p>
  
  <pre><code>...
  &lt;input asp-for="Email" class="form-control"&gt;
  &lt;div class="invalid-feedback" style="display:block;"&gt;
      &lt;span asp-validation-for="Email"&gt;&lt;/span&gt;
  &lt;/div&gt;
  ...
  </code></pre>
  
  <p>And I have the resource file Resources\SharedResource.resx</p>
  
  <p><strong>Email</strong>   Email<br>
  <strong>EmailIsNotValid</strong> The Email field is not a valid email address.<br>
  <strong>EmailRequired</strong>   The Email field is required.    </p>
  
  <p>Doesn't work, no errors during compilation or runtime. Instead of a translation, it shows me 'EmailIsNotValid' or 'EmailRequired'. What could go wrong?</p>