Resource (RESX) files messed up
Asked Answered
S

5

7

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.

Swami answered 27/7, 2010 at 12:56 Comment(0)
S
9

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.

Swami answered 27/7, 2010 at 13:54 Comment(2)
Yes, but only one file of all with the same root filename gets the auto designer code generated and that is the file with no language specifier. It makes sense because in code when you use it, you only use one class name (assuming we are talking about global resources and those are in Resources namespace, as by default).Swami
Sorry @mare, I was wrong :) resx is the "xml type" structure that contains the strings. you are wright though, there is only one code behind, that one is used to link the resx to the resourcemanager. ALTOOUUUGGHHH ... it generates a cs file for each resx (all empty except the default one)Protege
V
9

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
Vinnie answered 5/6, 2012 at 9:46 Comment(0)
P
2

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

Protege answered 27/7, 2010 at 13:8 Comment(6)
You know, this actually works until the step where I rename the new file, what was before Resource1.resx and had its designer file full of code, after renaming to Localize.sl.resx all the code in designer file is gone.Swami
hmmm, weird, is your custom tool set to GlobalResourceProxyGenerator. @edit Also check if you delete the old one, that in you windows folder (check outside VS) your old resx AND cs AND designer classes are deleted. I think they are still there but just excluded from your project in VSProtege
I figured out that apparently the dot is making him problems, because if I rename it to Resources54.resx it works fine. I think with the .lang identifier VS is trying to create Localize.sl or Localize.en class which of course he can't. Yes, that's my custom tool set. Any ideas?Swami
that is strange, I just did the exact same steps, In my App_Glob.. copied a resx and pasted it (with ctrl+c ctrl+v) and then renamed it to Localized.sl.resx without a problem. Is there any webserver still running from visual studio? if so stop them all. (still believe there may be some excluded files :))Protege
Hmmmm, this is sooo weird. If I rename it work Localize.sl2.resx the designer file is generated fine containing a class sl2 but if I name it Localize.sl.resx the designer file is empty. Is it possible "sl" being a reserved word in C#?Swami
No, it is not reserved, I tried it earlier + It wouldn't affect the system I think. Try creating a simple new project, add a resx, and name it somethin.sl.resx if this works, it means the name ... nameyouhave.sl.resx is locked by the system, and when VS wants to generate it, it cant because it would "override" the "locked" file-> then reboot will help :)Protege
D
0

Sorry for using this to write a comment. My reputation actually is less than 50 =( but i think this might be important too.

This referes to Alvis' answer: Your solution did the trick. But i had also to modify the access modifier of properties in the base designer code file from internal to public. Otherwise i got XmlParseExceptions when trying to access the resx in xaml.

Edit: So this referes to C#/WPF. Could be different in ASP.NET

Drysalter answered 17/9, 2015 at 13:54 Comment(0)
H
0

I found the best way was to:

  • Create the file as the default: Resource1.resx
  • Let it create the: Resource1.Desinger.cs
  • Rename it to what language you want, e.g., Localize.en.resx

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

Heartbreak answered 20/5, 2019 at 9:14 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.