Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / .NET Framework / New Users / November 2006

Tip: Looking for answers? Try searching our database.

Localization and satellite assembly problem

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Dale - 13 Nov 2006 06:02 GMT
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
Signature

Dale Preston
MCAD C#
MCSE, MCDBA

Linda Liu [MSFT] - 13 Nov 2006 10:45 GMT
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.
Linda Liu [MSFT] - 14 Nov 2006 10:06 GMT
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
Dale - 14 Nov 2006 16:51 GMT
Linda,

That was the problem.  Thanks for your help!

Dale

Signature

Dale Preston
MCAD C#
MCSE, MCDBA

> Hi Dale,
>
[quoted text clipped - 26 lines]
> Linda Liu
> Microsoft Online Community Support

Rate this thread:







Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.