Localization and satellite assembly problem

G

Guest

I am having a problem localizing a .Net 2.0 class library. This library is
called in a Windows.Forms application. My operating system language is en-US.

In the class library, I have a file, Resources.resx, which is set to be
embedded in the library's dll. This is working properly. I can get the
default resources using this code:

ResourceManager rm = new ResourceManager("MyLib.Resources",
Assembly.GetExecutingAssembly());

return rm.GetString("MyString");

This works. The second line does return the default language value for
MyString.

The problem is, the following line also returns the default language value
for MyString:

return rm.GetString("MyString", new CultureInfo("es-MX"));

I created the es-MX satellite assembly by placing a copy of Resources.resx
in the bin/Debug/es-MX folder under my project code and renaming it to
Resources.es-MX.resx. I changed the value of several resources for test and
then compiled Resources.es-MX.resx using:

resgen Resources.es-MX.resx Resources.es-MX.resources

and linked the satellite assembly using:

al /t:lib /embed:Resources.es-MX.resources /culture:es-MX
/out:MyLib.Resources.dll


When I run the application the class library, MyLib.dll, and the folder
es-MX, containing MyLib.Resources.dll, are copied to the bin/debug folder of
my application. The result is that in the debug folder of the application is
MyApp.exe and MyLib.dll and a folder named es-MX. In the folder es-MX is the
file MyLib.Resources.dll.

The application calls several string properties of objects defined in MyLib.
Each of these properties returns the default language text rather than the
es-MX text even though I am passing the "es-MX" culture as defined in the
line above.

When I debug the application and step through to the line where the resource
string is being returned, I can call Assembly.GetExecutingAssembly() in the
immediate window and see that the current assembly is, as I had hoped, MyLib
and not MyApp.

Thanks in advance for any help.

Dale
 
L

Linda Liu [MSFT]

Hi Dale,

Thank you for posting.

This is a quick note to let you know that I am researching on this issue
and will get it back to you ASAP.

I appreciate your patience.


Sincerely,
Linda Liu
Microsoft Online Community Support

==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif
ications.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscriptions/support/default.aspx.
==================================================

This posting is provided "AS IS" with no warranties, and confers no rights.
 
L

Linda Liu [MSFT]

Hi Dale,

I performed a test based on your description and sample code and did
reproduce the problem.

I spent several hours and found the reason finally! It is not because the
resource manager didn't find the satellite assembly but because the
embedded .resources file in the satellite assembly doesn't have a full
name. In this case, the full name is "MyLib.Resources.es-MX.resources", but
the .resources file's name is "Resources.es-MX.resources".

When you use the resgen tool to convert .resx file to common language
runtime binary .resources file, you should add the namespace name of your
project in the front of the converted .resources file. The following is a
sample.

resgen Resources.es-MX.resx MyLib.Resources.es-MX.resources

Thus, the .resources file has a full name. Then you use AL.exe tool to
boudle the .resource file into a satellite assembly and place this
satellite assembly to the es-MX subdirectory of the application's bin/debug
folder.

Run the application again and you should see the correct result.

Please try my suggestion and let me know the result.


Sincerely,
Linda Liu
Microsoft Online Community Support
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top