views:

269

answers:

2

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's but the designer files are gone (empty) so the application does not build.

Any suggestions?

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

+1  A: 

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

Nealv
Crazy series of steps :))
Leniel Macaferi
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.
mare
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 VS
Nealv
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?
mare
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 :))
Nealv
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#?
mare
No webserver running and yes, all files are shown.
mare
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.resxif 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 :)
Nealv
A: 

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.

mare
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).
mare
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)
Nealv