Search code examples
asp.net-mvcvisual-studiovisual-studio-2010resourcesresx

Resource (RESX) files messed up


I had a resource file named Localize.resx, which contains English strings. I copied and pasted it inside the same folder(App_GlobalResources), VS created a copy, I renamed the copy to Localize.sl.resx and the original to Localize.en.resx. Now everything in codebehind files (Localize.en.designer.cs) is gone. Deleting the designer file and selecting Run Custom Tool generates a new but completely blank designer file.

I still have all my strings in both resx files but the designer files are gone (empty) so the application does not build.

This is inside VS 2010 with an ASP.NET MVC solution.


Solution

  • This is what ASP.NET documentation says about resources files.

    It does not talk specifically about codebehind designer files generated on the fly but if you read the bolded text carefully, it is essentially saying that you need the base file without language specified and, given that, it makes sense that only this file will include autogenerated code.

    "When you create resource files, you start by creating a base .resx file. For each language that you want to support, create a new file that has the same file name. But in the name, include the language or the language and culture (culture name). For a list of culture names, see the CultureInfo class. For example, you might create the following files:

    •WebResources.resx

    The base resource file. This is the default (fallback) resource file.

    •WebResources.es.resx

    A resource file for Spanish.

    •WebResources.es-mx.resx

    A resource file for Spanish (Mexico) specifically.

    •WebResources.de.resx

    A resource file for German."

    I actually have never noticed this before but when I went to check my old projects, I saw they all have the base file and then language specific ones. So I just corrected it to follow that convention and it works now.