Resource Files (.resx) corrupted

I had a resource file called Localize.resx that contains English lines. I copied and pasted it into 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 the codebehind files (Localize.en.designer.cs) has disappeared. Deleting the constructor file and selecting the Run Custom Tool generates a new but completely empty constructor file.

I have all the lines in both resx, but the constructor files are gone (empty), so the application does not create.

Any suggestions?

This is inside Vs 2010 with ASP.NET MVC solution.

+7
visual-studio resources asp.net-mvc visual-studio-2010 resx
source share
5 answers

This is what the ASP.NET documentation says about resource files.

It does not specifically talk about code constructor files generated on the fly, but if you carefully read the highlighted in bold, they essentially say that you need a base file without the specified language, and given this, it makes sense that only this file will include auto generated code.

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

β€’ WebResources.resx

Base Resource File. This is the default resource file (backup).

β€’ WebResources.es.resx

Resource file for spanish.

β€’ WebResources.es-mx.resx

Resource File for Spanish (Mexico).

β€’ WebResources.de.resx

Resource file for the German language.

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

+8
source share

I had the same problem - Designer.cs file was not present for some resx files.

Fixed setting properties for resx files:

Build Action - Embedded Resource Custom Tool - PublicResXFileCodeGenerator 
+9
source share

If I were you, I would:

create a new resx file; open the old one; Press ctrl + a in the old one; Press ctrl + v in the new one; Save the new one; Delete old; Rename the new one :)

This should quickly solve the problem. You can also check if cs files are not excluded from the file by clicking the Show All button

+2
source share

Sorry to use this to write a comment. My reputation is actually less than 50 = (but I think it can be important too.

This refers to Alvis's answer: Your decision did the trick. But I also had to modify the property properties modifier in the base code of the designer code from internal to public. Otherwise, I got XmlParseExceptions when trying to access resx in xaml.

Edit: So this applies to C # / WPF. May vary in ASP.NET

0
source share

I found that the best way was:

  • Create a default file: Resource1.resx
  • Let him create: Resource1.Desinger.cs
  • Rename it to your preferred language, for example Localize.en.resx

Any other way for me just stopped creating X.Designer.cs files

0
source share

All Articles