Take the 2-minute tour ×

I've just come across the weirdest behavior in Visual Studio 2010 while working with Resx resource files and I just can't wrap my head around it.

The problem is as follows: Visual Studio will not generate the designer.cs file for a resource file with a localized name (such as resource.fr.resx), but it works fine for other files with simple names (such as resource.resx).

Here's a snapshot of my visual studio project setup:

enter image description here

As you can see I just did a simple test with 3 resource files:

  • test.resx
  • test2.resx
  • test.fr.resx

The designer.cs files for test.resx and test2.resx are generated just fine. However test.fr.designer.cs is created but always blank, no matter what I do.

I have double and triple checked: the custom tool property is properly set for the localized file. All properties are exactly the same across all files (I'm using PublicResxFileCodeGenerator, but I get the same behavior if I set access modifier to internal and use ResxFileCodeGenerator).

Note: I've noticed that when created a resource file, Visual Studio normally defaults the access modifier to "Internal". However, when creating a localized resource file (resource.fr.resx) it defaults to "No code generation". Just found that interesting to note since it proves that visual Studio is treating the localized file differently for some reason.

--> Is there something I'm missing here? I would appreciate if anybody has some insight on the subject, this is driving me crazy.

share|improve this question
add comment

1 Answer

up vote 13 down vote accepted

While I haven't looked into this particular issue, I've had numerous other problems with ".resx" files. Visual Studio is sometimes buggy (handling ".resx" files among other things), and I've officially reported some of these to MSFT (since it affects my own commercial localization program). In any case, you shouldn't normally be naming things this way. It effectively violates MSFT's localization rules. Default language files shouldn't normally have an embedded language code, and it could be choking on it for this reason. I'd need to investigate, but what you should be doing is creating "Test.resx", which has a "Designer.cs" file, and then "Test.fr.resx", which doesn't. All default language strings are then placed in "Test.resx" and the corresponding French strings in "Test.fr.resx". In code, you then access the strongly typed name found in "Test.Designer.cs", and the string you get back will be the default language string unless you set "System.Threading.Thread.CurrentThread.CurrentUICulture" to "fr". You'll then get back the French version of the string from "Test.fr.resx", unless it's not found there (there's no translation), in which case you'll get back the fallback string from "Test.resx" (i.e., the default language string). This is how the hub-and-spoke model basically works.

share|improve this answer
I guess I was just missunderstanding the way it's supposed to work then. However, the resource manager is not finding my localized strings which is what took me to investigate this whole thing. But this could be for another reason. I'll investigate again under the assumption that nothing's wrong with the resource files. –  Aerendel Aug 17 '12 at 20:34
Ok, try it the way I described however and it should work. –  Larry Aug 17 '12 at 20:36
Indeed, I didn't understand that the framework only needs to generate code for the master resource file which led me in the wrong direction. Thanks for explaining and pointing that out! Visual Studio does indeed chocke on generating code for a file that follows the localized naming convention, which does actually make sense. Everything's working now after changing the localized files back to "No code genration". Thanks a lot! –  Aerendel Aug 17 '12 at 20:46
NP. Note (FYI only) that you can also use the "Resources.Resx" file that's automatically created under the "Properties" folder. If you don't see it, then right-click the project in Solution Explorer, select "Properties" and take a look at the "Resources" tab in the resulting window (running down the left-hand side). –  Larry Aug 17 '12 at 20:53
add comment

Your Answer


