Question

I have a class library - call it Framework. In the assemblyinfo.cs, I have:

[assembly: NeutralResourcesLanguage("en-US")]

Under a \Resources\ directory, I have FrameworkResources.resx and FrameworkResources.fr-FR.resx

In a helper class, I am using this as my resource manager:

private static ResourceManager manager = new ResourceManager("Framework.Resources.FrameworkResources", Assembly.GetExecutingAssembly());

In code, if I do something like this:

String message = manager.GetString("ArgumentNullExceptionMessage", CultureInfo.CurrentCulture);

I can debug and hover over CurrentCulture and it (and UICulture) are set to fr-FR, yet this ALWAYS brings back my default, english message - NOT the French message from the fr-FR resource file.

Should ResourceManager automatically wire that up, or should I be writing code to query the current culture, then open the right file? Am I incorrect in assuming that Resource Manager will know to get the fr-FR string, because that is the current culture?

I'm not sure why this isn't working.

UPDATE: I have satellite assemblies, so believe the compilation part is going OK. I think the problem is in my resource manager. I tried using ResourceSets and using ResourceManager explicitly like this:

ResourceManager manager =
    new ResourceManager("Framework.Resources.FrameworkResources",
        Assembly.GetExecutingAssembly());

Debug.WriteLine("de-DE : " + manager.GetString(resourceName, new CultureInfo("de-DE")));
Debug.WriteLine("el    : " + manager.GetString(resourceName, new CultureInfo("el")));
Debug.WriteLine("es-MX : " + manager.GetString(resourceName, new CultureInfo("es-MX")));
Debug.WriteLine("fr-FR : " + manager.GetString(resourceName, new CultureInfo("fr-FR")));
Debug.WriteLine("hi    : " + manager.GetString(resourceName, new CultureInfo("hi")));
Debug.WriteLine("zh-CN : " + manager.GetString(resourceName, new CultureInfo("zh-CN")));

That results in this:

de-DE : Argument '%ArgumentName%' cannot be null or empty.
el    : Argument '%ArgumentName%' cannot be null or empty.
es-MX : Argument '%ArgumentName%' cannot be null or empty.
fr-FR : Argument '%ArgumentName%' cannot be null or empty.
hi    : Argument '%ArgumentName%' cannot be null or empty.
zh-CN : Argument '%ArgumentName%' cannot be null or empty.

So, even though everything is in place, my resource manager simply isn't trying to look in those satellite assemblies. And to be clear, in those assemblies, I have the translated version of the string above - so it's definitely reading from my default FrameworkResources.resx file, instead of the culture-specific ones.

Was it helpful?

Solution

I figured it out (thanks to more scouring on the interweb). I was running code from unit tests, and apperently MSTest doesn't "deploy" the satellite assemblies. If I go into the Test Settings and turn off "Deployment", everything works as expected. Ugh!

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top