all groups > dotnet internationalization > february 2005 >
You're in the

dotnet internationalization

group:

Localized strings in dynamically loaded assemblies not retrieved


Localized strings in dynamically loaded assemblies not retrieved Ben Cline
2/26/2005 12:03:06 AM
dotnet internationalization:
I seem to be having a problem accessing the resource information in
dynamically loaded assemblies.

This best explained using an example.
I have a class called TestClass in a Test.dll. Using a TestClass.resx,
TestClass.de.resx and a TestClass.de-AT.resx I can compile to the following
structure.
..\Test.dll
..\de\Test.resources.dll
..\de-AT\Test.resources.dll

I can reference the dll directly in my VB program and get the texts, no
problem. I am using code a little like the following:

Dim ass as [Assembly] =
system.Reflection.Assembly.GetAssembly(GetType(TestClass))
Dim types() As Type = ass.GetTypes
Dim rm As ResourceManager
Dim resourceNameAttributes() As Object

For Each t As Type In Types
rm = New ResourceManager(t.FullName, t.Assembly)

resourceNameAttributes =
t.GetCustomAttributes(GetType(ResourceNameAttribute), True)
Dim resourceAtt As ResourceAttribute =
DirectCast(resourceNameAttributes(0), resourceAtt)
Debug.Writeline rm.GetString(resourceAtt.ResourceName)
Next

This works fine and I can see all my strings in the correct languages if I
do something like
Threading.Thread.CurrentThread.CurrentUICulture = New
System.Globalization.CultureInfo("de-AT")

the correct strings are retrieved.

The problem arises if I try to dynamically load the dll. I am doing
something like...

Dim ass as [Assembly] = [Assembly].LoadFile(".\test.dll")
'... The rest of the code is the same.


I get invariant resource infomation but the localized texts are not being
loaded. Is there some trick to this? How can I get the resourcemanager to
'know' there should be resource.dll's availible? Any ideas?

Thanks in advance
Still no answer?? Ben Cline
3/3/2005 2:43:05 AM
Hi all,

Ok, I MAY have identified the problem. I am loading my assemblies in a new
AppDomain. I would like to change to UICulture in that domain but I can't
seem to find any way of doing that.

So new question, is there a way to set the Culture on a dynamically created
AppDomain?

Thanks
RE: Still no answer?? Olivier Guinart [MS]
3/16/2005 3:25:03 PM
Hi Ben,

Have you tried the function AppDomain.CreateInstance ? There are 3
signatures for that function, and one takes the culture attribute as a
parameter.(http://msdn.microsoft.com/library/en-us/cpref/html/frlrfSystemAppDomainClassCreateInstanceTopic3.asp?frame=true)
Please take a look also at the remark from that topic.

It's unclear whether passing the culture will only help in parsing the
arguments, or if the satellite assemblies will be loaded as expected, but it
might be worth a try.

Otherwise, from your code, it looks like you're forcing the resources to be
loaded from the main assembly anyway, because you hard-coded the DLL name to
look for. So why would the resourcemanager class look for another assembly in
this case ? Have you tried Dim ass as [Assembly] =
[Assembly].LoadFile(".\de-AT\test.resources.dll")? If that works, and you end
up being able to only load de-AT resources, then you'll have to build that
path string yourself.

Please let us know if this helps.

Lynne, Masayoshi, Olivier.
lynnedong@hotmail.com, msmayada@hotmail.com, olivierg@online.microsoft.com

-Please do not send email directly to this alias. This alias is for
newsgroup purposes only
-This posting is provided “AS IS” with no warranties, and confers no rights.

[quoted text, click to view]
AddThis Social Bookmark Button