Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 486
mare Avatar asked Jul 27 '10 12:07

mare


People also ask

How do you regenerate a RESX file?

If so, go to project properties, then the "Resources" tab, and there should be a big link to click to regenerate it.

What is a resource RESX file?

The . resx resource file format consists of XML entries that specify objects and strings inside XML tags. One advantage of a . resx file is that when opened with a text editor (such as Notepad) it can be written to, parsed, and manipulated.

Are RESX files compiled?

resx files are compiled into binary . resources files.


3 Answers

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.

like image 142
mare Avatar answered Nov 09 '22 14:11

mare


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

The fix was to set the properties for the resx files:

Build Action - Embedded Resource
Custom Tool  - PublicResXFileCodeGenerator
like image 31
Alvis Avatar answered Nov 09 '22 13:11

Alvis


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 the old one; Rename the new one :)

This should solve the problem quiet fast. You could also check if the cs files are not excluded from the file by clicking the show all button

like image 25
Nealv Avatar answered Nov 09 '22 15:11

Nealv