title: MVC 6 : how to use RESX files?
body: <p>I am trying to migrate my existing ASP.NET MVC 5 project to  MVC 6 vNext project , while I have been able to get through and resolve most of the issues , I cant seem to find any documentation on how to use the RESX resource files for localization in MVC 6 </p>
  
  <p>My ViewModels are using statements like </p>
  
  <pre><code> [Required(ErrorMessageResourceType = typeof(Resources.MyProj.Messages), ErrorMessageResourceName = "FieldRequired")]
  </code></pre>
  
  <p>This worked fine in MVC 5 as long as the RESX was included properly and the access modifiers were set correctly , but it doesnt seem to work in a vNext project 
  Does anyone know how RESX can be used in MVC 6 vNext projects ? </p>
  
  <p>I saw a few posts here and on the GIT hub site which say that the localization story for ASP.NET 5 / MVC 6 is complete but I cant find any decent sample where the resource strings have been used. </p>
  
  <p>Using the code above gives me a error </p>
  
  <blockquote>
    <p>Error CS0246  The type or namespace name 'Resources' could not be found
    (are you missing a using directive or an assembly reference?)</p>
  </blockquote>
  
  <p>Edit : Changed text to clarify that I am looking for implementation of localization in vNext ( MVC 6 )projects , I am able to make it work in MVC 5.</p>
  
  <p>Edit 2 : Got the localization bit working after implementing the answer from Mohammed but I am stuck at a new error now.</p>
  
  <p>Once I Include </p>
  
  <pre><code>  "Microsoft.AspNet.Localization": "1.0.0-beta7-10364",
      "Microsoft.Framework.Localization": "1.0.0-beta7-10364",
  </code></pre>
  
  <p>packages and add the following line in ConfigureServices in the Startup.cs </p>
  
  <pre><code>   services.AddMvcLocalization();
  </code></pre>
  
  <p>I get a new error  when the following code is getting executed.</p>
  
  <pre><code>  public class HomeController : Controller
      {
          private readonly IHtmlLocalizer _localizer;
  
          public HomeController(IHtmlLocalizer&lt;HomeController&gt; localizer)
          {
              _localizer = localizer;
          }
            ....
  </code></pre>
  
  <p>Error : </p>
  
  <blockquote>
    <p>An unhandled exception occurred while processing the request.</p>
    
    <p>InvalidOperationException: Unable to resolve service for type
    'Microsoft.Framework.Runtime.IApplicationEnvironment' while attempting
    to activate
    'Microsoft.Framework.Localization.ResourceManagerStringLocalizerFactory'.
    Microsoft.Framework.DependencyInjection.ServiceLookup.Service.CreateCallSite(ServiceProvider
    provider, ISet`1 callSiteChain)</p>
  </blockquote>
  
  <p>Cant figure out if its a dependency i am missing or there is a issue in the code </p>
  
  <p><strong>Edit 3 :</strong></p>
  
  <p>To anyone still looking for a solution. At this point in time , you can use the code in the answer  by <strong>Muhammad Rehan Saee</strong> to get localization support in your CSHTML. However the story for enabling localization in validation attributes is not yet done( at the time of this edit : 08/Sep/2015) 
  Have a look at the issue on the GITHUB site for mvc below : </p>
  
  <p><a href="https://github.com/aspnet/Mvc/issues/2766#issuecomment-137192942" rel="noreferrer">https://github.com/aspnet/Mvc/issues/2766#issuecomment-137192942</a></p>
  
  <p>PS : To fix the InvalidOperationException  I did the following</p>
  
  <blockquote>
    <p>Taking all dependencies as the beta7-* and clearing all the contents
    of my C:\Users\.dnx\packages got rid of the error.</p>
  </blockquote>
  
  <p>Details on the issue I raised : </p>
  
  <p><a href="https://github.com/aspnet/Mvc/issues/2893#issuecomment-127164729" rel="noreferrer">https://github.com/aspnet/Mvc/issues/2893#issuecomment-127164729</a></p>
  
  <p>Edit : 25 / Dec /2015 </p>
  
  <p>This is finally working in MVC 6 now.</p>
  
  <p>Wrote a quick blog post here : <a href="http://pratikvasani.github.io/archive/2015/12/25/MVC-6-localization-how-to/" rel="noreferrer">http://pratikvasani.github.io/archive/2015/12/25/MVC-6-localization-how-to/</a></p>