Resource access and culture info

G

Gary

am having some trouble accessing culture specific resources using Vs.Net
2005, what process have I missed?


* Created a Windows Forms Application called GlobalTest
* Created the following code in button1_Click :

ResourceManager rm = new ResourceManager("strings",
this.GetType().Assembly);
CultureInfo ci = new CultureInfo("en-US");

MessageBox.Show(rm.GetString("test", ci));

* Added a file called 'strings.en-US.resx' to my project and created a
string entry with the name 'test' and a value of 'hello world'.

Created a key.snk using sn -k key.snk at the VS2005 command prompt and
signed my Windows Application with it.

VS.NET 2005 builds the application and satellite assembly with the following
parameters -



C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\Csc.exe /noconfig
/nowarn:1701,1702 /errorreport:prompt /warn:4 /define:DEBUG;TRACE
/reference:C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\System.Data.dll
/reference:C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\System.Deployment.dll
/reference:C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\System.dll
/reference:C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\System.Drawing.dll
/reference:C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\System.Windows.Forms.dll
/reference:C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\System.Xml.dll
/debug+ /debug:full /keyfile:key.snk /optimize-
/out:blush:bj\Debug\GlobalTest.exe /resource:blush:bj\Debug\GlobalTest.Form1.resources
/resource:blush:bj\Debug\GlobalTest.Properties.Resources.resources /target:winexe
Form1.cs Form1.Designer.cs Program.cs Properties\AssemblyInfo.cs
Properties\Resources.Designer.cs Properties\Settings.Designer.cs

Compile complete -- 0 errors, 0 warnings

C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\AL.exe /culture:en-US
/keyfile:key.snk /out:blush:bj\Debug\en-US\GlobalTest.resources.dll
/template:blush:bj\Debug\GlobalTest.exe
/embed:blush:bj\Debug\GlobalTest.strings.en-US.resources

GlobalTest -> C:\Documents and Settings\gary\My Documents\Visual Studio
2005\Projects\GlobalTest\GlobalTest\bin\Debug\GlobalTest.exe





I get the following error message -

System.Resources.MissingManifestResourceException: Could not find any
resources appropriate for the specified culture or the neutral culture.
Make sure "strings.resources" was correctly embedded or linked into assembly
"GlobalTest" at compile time, or that all the satellite assemblies required
are loadable and fully signed.
at System.Resources.ResourceManager.InternalGetResourceSet(CultureInfo
culture, Boolean createIfNotExists, Boolean tryParents)
at System.Resources.ResourceManager.InternalGetResourceSet(CultureInfo
culture, Boolean createIfNotExists, Boolean tryParents)
at System.Resources.ResourceManager.InternalGetResourceSet(CultureInfo
culture, Boolean createIfNotExists, Boolean tryParents)
at System.Resources.ResourceManager.GetString(String name, CultureInfo
culture)
at GlobalTest.Form1.button1_Click(Object sender, EventArgs e) in
C:\Documents and Settings\gary\My Documents\Visual Studio
2005\Projects\GlobalTest\GlobalTest\Form1.cs:line 27
 
R

Richard Grimes

Gary said:
am having some trouble accessing culture specific resources using
Vs.Net 2005, what process have I missed?


* Created a Windows Forms Application called GlobalTest
* Created the following code in button1_Click :

ResourceManager rm = new ResourceManager("strings",
this.GetType().Assembly);
CultureInfo ci = new CultureInfo("en-US");

Is there a reason why you explicitly set the culture? If you do not do
this the ResourceManager class will get the culture from the machine,
which is usually the best thing to do.
MessageBox.Show(rm.GetString("test", ci));

* Added a file called 'strings.en-US.resx' to my project and created a
string entry with the name 'test' and a value of 'hello world'.

Is this an XML file? It should be. You can have non XML resources, in
which case they are string files with lines in the format name=value

You must compile the .resx
Created a key.snk using sn -k key.snk at the VS2005 command prompt and
signed my Windows Application with it.

Why? There are few reasons to sign an application.
VS.NET 2005 builds the application and satellite assembly with the
following parameters -

You don't seem to have a line for resgen.
System.Resources.MissingManifestResourceException: Could not find any
resources appropriate for the specified culture or the neutral
culture. Make sure "strings.resources" was correctly embedded or
linked into assembly "GlobalTest" at compile time, or that all the
satellite assemblies required are loadable and fully signed.

This tells you a lot. You have two resources in the main assembly:

GlobalTest.Form1.resources
GlobalTest.Properties.Resources.resources

and the satellite has one resource

GlobalTest.strings.en-US.resources

The first error is that the main assembly should have the *neutral*
resource called GlobalTest.strings.resources so that if the requested
localized resource cannot be found the ResourceManager will fall back to
the neutral resource. This is the convention.

Also, check the that the resource requested when you create the
ResourceManager is the same name as in the main assembly and the
satellite (taking the localisation into account, but omitting the
..resources part). Since the satellite has a resource called
GlobalTest.strings.en-US.resources the parameter to ResourceManager
should be GlobalTest.strings.

More details can be found in my Fusion workshop:

http://www.grimes.demon.co.uk/workshops/fusWSNine.htm

Richard
 
S

Steven Cheng[MSFT]

Thanks for Richard's infomative inputs.

Hi Gary,

Actually the globalization architecture in .NET 2.0 dosn't differ much
(from underlying fundatmental perspective....) from .NET 1.x...). As for
loading the resource file in our winform application through
ResourceManager class, one thing we need to pay attention is that the
"resource name" we passed in the ResourceManager's constructor is namespace
sensitive. So suppose our winform application's default namespace is
"GlobalApp", and we put a resx file named "mystrings.xx-XX.resx" in the
project, when we try loading in the code, we should use the following means:

=================
private void btnGetString_Click(object sender, EventArgs e)
{
CultureInfo ci = new CultureInfo("zh-CN");
ResourceManager rm = new ResourceManager("GlobalApp.mystrings",
this.GetType().Assembly);
string hw = rm.GetString("HELLOWORLD",ci);

MessageBox.Show(hw);
}
=================

notice that the resource file name is "GlobalApp.mystrings" rather than
"mystrings" since namespace is also required....

In addition, I strongly agree with Richard's opinion on providing a default
netural resource file at the very beginning (before we add other culture
specific resource files.....). This can help our application always get a
default fallback resource when can not find a certain specifc culture's
resource.....

Thanks,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)



--------------------
| From: "Richard Grimes" <[email protected]>
| References: <#[email protected]>
| Subject: Re: Resource access and culture info
| Date: Fri, 25 Nov 2005 22:20:31 -0000
| Lines: 73
| X-Priority: 3
| X-MSMail-Priority: Normal
| X-Newsreader: Microsoft Outlook Express 6.00.2900.2527
| X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.2527
| X-RFC2646: Format=Flowed; Response
| Message-ID: <[email protected]>
| Newsgroups: microsoft.public.dotnet.framework
| NNTP-Posting-Host: grimes.gotadsl.co.uk 62.3.255.233
| Path: TK2MSFTNGXA02.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFTNGP15.phx.gbl
| Xref: TK2MSFTNGXA02.phx.gbl microsoft.public.dotnet.framework:104195
| X-Tomcat-NG: microsoft.public.dotnet.framework
|
| Gary wrote:
| > am having some trouble accessing culture specific resources using
| > Vs.Net 2005, what process have I missed?
| >
| >
| > * Created a Windows Forms Application called GlobalTest
| > * Created the following code in button1_Click :
| >
| > ResourceManager rm = new ResourceManager("strings",
| > this.GetType().Assembly);
| > CultureInfo ci = new CultureInfo("en-US");
|
| Is there a reason why you explicitly set the culture? If you do not do
| this the ResourceManager class will get the culture from the machine,
| which is usually the best thing to do.
|
| > MessageBox.Show(rm.GetString("test", ci));
| >
| > * Added a file called 'strings.en-US.resx' to my project and created a
| > string entry with the name 'test' and a value of 'hello world'.
|
| Is this an XML file? It should be. You can have non XML resources, in
| which case they are string files with lines in the format name=value
|
| You must compile the .resx
|
| > Created a key.snk using sn -k key.snk at the VS2005 command prompt and
| > signed my Windows Application with it.
|
| Why? There are few reasons to sign an application.
|
| > VS.NET 2005 builds the application and satellite assembly with the
| > following parameters -
|
| You don't seem to have a line for resgen.
|
| > System.Resources.MissingManifestResourceException: Could not find any
| > resources appropriate for the specified culture or the neutral
| > culture. Make sure "strings.resources" was correctly embedded or
| > linked into assembly "GlobalTest" at compile time, or that all the
| > satellite assemblies required are loadable and fully signed.
|
| This tells you a lot. You have two resources in the main assembly:
|
| GlobalTest.Form1.resources
| GlobalTest.Properties.Resources.resources
|
| and the satellite has one resource
|
| GlobalTest.strings.en-US.resources
|
| The first error is that the main assembly should have the *neutral*
| resource called GlobalTest.strings.resources so that if the requested
| localized resource cannot be found the ResourceManager will fall back to
| the neutral resource. This is the convention.
|
| Also, check the that the resource requested when you create the
| ResourceManager is the same name as in the main assembly and the
| satellite (taking the localisation into account, but omitting the
| .resources part). Since the satellite has a resource called
| GlobalTest.strings.en-US.resources the parameter to ResourceManager
| should be GlobalTest.strings.
|
| More details can be found in my Fusion workshop:
|
| http://www.grimes.demon.co.uk/workshops/fusWSNine.htm
|
| Richard
| --
| http://www.grimes.demon.co.uk/workshops/fusionWS.htm
| http://www.grimes.demon.co.uk/workshops/securityWS.htm
|
|
|
 
S

Steven Cheng[MSFT]

Hi Gary,

How are you doing on this issue? Does the suggestions in my last reply
helps a little? If there're anything else we can help, please feel free to
post here.

Thanks & Regards,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)
--------------------
| X-Tomcat-ID: 51353266
| References: <#[email protected]>
<[email protected]>
| MIME-Version: 1.0
| Content-Type: text/plain
| Content-Transfer-Encoding: 7bit
| From: (e-mail address removed) (Steven Cheng[MSFT])
| Organization: Microsoft
| Date: Mon, 28 Nov 2005 03:22:30 GMT
| Subject: Re: Resource access and culture info
| X-Tomcat-NG: microsoft.public.dotnet.framework
| Message-ID: <[email protected]>
| Newsgroups: microsoft.public.dotnet.framework
| Lines: 132
| Path: TK2MSFTNGXA02.phx.gbl
| Xref: TK2MSFTNGXA02.phx.gbl microsoft.public.dotnet.framework:104249
| NNTP-Posting-Host: tomcatimport2.phx.gbl 10.201.218.182
|
| Thanks for Richard's infomative inputs.
|
| Hi Gary,
|
| Actually the globalization architecture in .NET 2.0 dosn't differ much
| (from underlying fundatmental perspective....) from .NET 1.x...). As
for
| loading the resource file in our winform application through
| ResourceManager class, one thing we need to pay attention is that the
| "resource name" we passed in the ResourceManager's constructor is
namespace
| sensitive. So suppose our winform application's default namespace is
| "GlobalApp", and we put a resx file named "mystrings.xx-XX.resx" in the
| project, when we try loading in the code, we should use the following
means:
|
| =================
| private void btnGetString_Click(object sender, EventArgs e)
| {
| CultureInfo ci = new CultureInfo("zh-CN");
| ResourceManager rm = new
ResourceManager("GlobalApp.mystrings",
| this.GetType().Assembly);
| string hw = rm.GetString("HELLOWORLD",ci);
|
| MessageBox.Show(hw);
| }
| =================
|
| notice that the resource file name is "GlobalApp.mystrings" rather than
| "mystrings" since namespace is also required....
|
| In addition, I strongly agree with Richard's opinion on providing a
default
| netural resource file at the very beginning (before we add other culture
| specific resource files.....). This can help our application always get a
| default fallback resource when can not find a certain specifc culture's
| resource.....
|
| Thanks,
|
| Steven Cheng
| Microsoft Online Support
|
| Get Secure! www.microsoft.com/security
| (This posting is provided "AS IS", with no warranties, and confers no
| rights.)
|
|
|
| --------------------
| | From: "Richard Grimes" <[email protected]>
| | References: <#[email protected]>
| | Subject: Re: Resource access and culture info
| | Date: Fri, 25 Nov 2005 22:20:31 -0000
| | Lines: 73
| | X-Priority: 3
| | X-MSMail-Priority: Normal
| | X-Newsreader: Microsoft Outlook Express 6.00.2900.2527
| | X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.2527
| | X-RFC2646: Format=Flowed; Response
| | Message-ID: <[email protected]>
| | Newsgroups: microsoft.public.dotnet.framework
| | NNTP-Posting-Host: grimes.gotadsl.co.uk 62.3.255.233
| | Path: TK2MSFTNGXA02.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFTNGP15.phx.gbl
| | Xref: TK2MSFTNGXA02.phx.gbl microsoft.public.dotnet.framework:104195
| | X-Tomcat-NG: microsoft.public.dotnet.framework
| |
| | Gary wrote:
| | > am having some trouble accessing culture specific resources using
| | > Vs.Net 2005, what process have I missed?
| | >
| | >
| | > * Created a Windows Forms Application called GlobalTest
| | > * Created the following code in button1_Click :
| | >
| | > ResourceManager rm = new ResourceManager("strings",
| | > this.GetType().Assembly);
| | > CultureInfo ci = new CultureInfo("en-US");
| |
| | Is there a reason why you explicitly set the culture? If you do not do
| | this the ResourceManager class will get the culture from the machine,
| | which is usually the best thing to do.
| |
| | > MessageBox.Show(rm.GetString("test", ci));
| | >
| | > * Added a file called 'strings.en-US.resx' to my project and created a
| | > string entry with the name 'test' and a value of 'hello world'.
| |
| | Is this an XML file? It should be. You can have non XML resources, in
| | which case they are string files with lines in the format name=value
| |
| | You must compile the .resx
| |
| | > Created a key.snk using sn -k key.snk at the VS2005 command prompt and
| | > signed my Windows Application with it.
| |
| | Why? There are few reasons to sign an application.
| |
| | > VS.NET 2005 builds the application and satellite assembly with the
| | > following parameters -
| |
| | You don't seem to have a line for resgen.
| |
| | > System.Resources.MissingManifestResourceException: Could not find any
| | > resources appropriate for the specified culture or the neutral
| | > culture. Make sure "strings.resources" was correctly embedded or
| | > linked into assembly "GlobalTest" at compile time, or that all the
| | > satellite assemblies required are loadable and fully signed.
| |
| | This tells you a lot. You have two resources in the main assembly:
| |
| | GlobalTest.Form1.resources
| | GlobalTest.Properties.Resources.resources
| |
| | and the satellite has one resource
| |
| | GlobalTest.strings.en-US.resources
| |
| | The first error is that the main assembly should have the *neutral*
| | resource called GlobalTest.strings.resources so that if the requested
| | localized resource cannot be found the ResourceManager will fall back
to
| | the neutral resource. This is the convention.
| |
| | Also, check the that the resource requested when you create the
| | ResourceManager is the same name as in the main assembly and the
| | satellite (taking the localisation into account, but omitting the
| | .resources part). Since the satellite has a resource called
| | GlobalTest.strings.en-US.resources the parameter to ResourceManager
| | should be GlobalTest.strings.
| |
| | More details can be found in my Fusion workshop:
| |
| | http://www.grimes.demon.co.uk/workshops/fusWSNine.htm
| |
| | Richard
| | --
| | http://www.grimes.demon.co.uk/workshops/fusionWS.htm
| | http://www.grimes.demon.co.uk/workshops/securityWS.htm
| |
| |
| |
|
|
 
G

Gary

Hi Steven,

It was purely not including the namespace.

Once I used 'GlobalTest.strings' instead of just 'strings' it worked fine.

Running through the documentation this was not clear, maybe I missed
something or the wording is not clear regarding the use of namespaces as I
imagined passing the Assembly as a parameter would have meant I was using
resources from that namespace. Documentation used -

http://msdn.microsoft.com/library/d...-us/cpguide/html/cpconLocalizingResources.asp

As for using a fallback namespace yes I agree but this was just a test
application for making a localizable application.



Thanks,

Gary




Steven Cheng said:
Hi Gary,

How are you doing on this issue? Does the suggestions in my last reply
helps a little? If there're anything else we can help, please feel free to
post here.

Thanks & Regards,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)
--------------------
| X-Tomcat-ID: 51353266
| References: <#[email protected]>
<[email protected]>
| MIME-Version: 1.0
| Content-Type: text/plain
| Content-Transfer-Encoding: 7bit
| From: (e-mail address removed) (Steven Cheng[MSFT])
| Organization: Microsoft
| Date: Mon, 28 Nov 2005 03:22:30 GMT
| Subject: Re: Resource access and culture info
| X-Tomcat-NG: microsoft.public.dotnet.framework
| Message-ID: <[email protected]>
| Newsgroups: microsoft.public.dotnet.framework
| Lines: 132
| Path: TK2MSFTNGXA02.phx.gbl
| Xref: TK2MSFTNGXA02.phx.gbl microsoft.public.dotnet.framework:104249
| NNTP-Posting-Host: tomcatimport2.phx.gbl 10.201.218.182
|
| Thanks for Richard's infomative inputs.
|
| Hi Gary,
|
| Actually the globalization architecture in .NET 2.0 dosn't differ much
| (from underlying fundatmental perspective....) from .NET 1.x...). As
for
| loading the resource file in our winform application through
| ResourceManager class, one thing we need to pay attention is that the
| "resource name" we passed in the ResourceManager's constructor is
namespace
| sensitive. So suppose our winform application's default namespace is
| "GlobalApp", and we put a resx file named "mystrings.xx-XX.resx" in the
| project, when we try loading in the code, we should use the following
means:
|
| =================
| private void btnGetString_Click(object sender, EventArgs e)
| {
| CultureInfo ci = new CultureInfo("zh-CN");
| ResourceManager rm = new
ResourceManager("GlobalApp.mystrings",
| this.GetType().Assembly);
| string hw = rm.GetString("HELLOWORLD",ci);
|
| MessageBox.Show(hw);
| }
| =================
|
| notice that the resource file name is "GlobalApp.mystrings" rather than
| "mystrings" since namespace is also required....
|
| In addition, I strongly agree with Richard's opinion on providing a
default
| netural resource file at the very beginning (before we add other culture
| specific resource files.....). This can help our application always get
a
| default fallback resource when can not find a certain specifc culture's
| resource.....
|
| Thanks,
|
| Steven Cheng
| Microsoft Online Support
|
| Get Secure! www.microsoft.com/security
| (This posting is provided "AS IS", with no warranties, and confers no
| rights.)
|
|
|
| --------------------
| | From: "Richard Grimes" <[email protected]>
| | References: <#[email protected]>
| | Subject: Re: Resource access and culture info
| | Date: Fri, 25 Nov 2005 22:20:31 -0000
| | Lines: 73
| | X-Priority: 3
| | X-MSMail-Priority: Normal
| | X-Newsreader: Microsoft Outlook Express 6.00.2900.2527
| | X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.2527
| | X-RFC2646: Format=Flowed; Response
| | Message-ID: <[email protected]>
| | Newsgroups: microsoft.public.dotnet.framework
| | NNTP-Posting-Host: grimes.gotadsl.co.uk 62.3.255.233
| | Path: TK2MSFTNGXA02.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFTNGP15.phx.gbl
| | Xref: TK2MSFTNGXA02.phx.gbl microsoft.public.dotnet.framework:104195
| | X-Tomcat-NG: microsoft.public.dotnet.framework
| |
| | Gary wrote:
| | > am having some trouble accessing culture specific resources using
| | > Vs.Net 2005, what process have I missed?
| | >
| | >
| | > * Created a Windows Forms Application called GlobalTest
| | > * Created the following code in button1_Click :
| | >
| | > ResourceManager rm = new ResourceManager("strings",
| | > this.GetType().Assembly);
| | > CultureInfo ci = new CultureInfo("en-US");
| |
| | Is there a reason why you explicitly set the culture? If you do not do
| | this the ResourceManager class will get the culture from the machine,
| | which is usually the best thing to do.
| |
| | > MessageBox.Show(rm.GetString("test", ci));
| | >
| | > * Added a file called 'strings.en-US.resx' to my project and created
a
| | > string entry with the name 'test' and a value of 'hello world'.
| |
| | Is this an XML file? It should be. You can have non XML resources, in
| | which case they are string files with lines in the format name=value
| |
| | You must compile the .resx
| |
| | > Created a key.snk using sn -k key.snk at the VS2005 command prompt
and
| | > signed my Windows Application with it.
| |
| | Why? There are few reasons to sign an application.
| |
| | > VS.NET 2005 builds the application and satellite assembly with the
| | > following parameters -
| |
| | You don't seem to have a line for resgen.
| |
| | > System.Resources.MissingManifestResourceException: Could not find
any
| | > resources appropriate for the specified culture or the neutral
| | > culture. Make sure "strings.resources" was correctly embedded or
| | > linked into assembly "GlobalTest" at compile time, or that all the
| | > satellite assemblies required are loadable and fully signed.
| |
| | This tells you a lot. You have two resources in the main assembly:
| |
| | GlobalTest.Form1.resources
| | GlobalTest.Properties.Resources.resources
| |
| | and the satellite has one resource
| |
| | GlobalTest.strings.en-US.resources
| |
| | The first error is that the main assembly should have the *neutral*
| | resource called GlobalTest.strings.resources so that if the requested
| | localized resource cannot be found the ResourceManager will fall back
to
| | the neutral resource. This is the convention.
| |
| | Also, check the that the resource requested when you create the
| | ResourceManager is the same name as in the main assembly and the
| | satellite (taking the localisation into account, but omitting the
| | .resources part). Since the satellite has a resource called
| | GlobalTest.strings.en-US.resources the parameter to ResourceManager
| | should be GlobalTest.strings.
| |
| | More details can be found in my Fusion workshop:
| |
| | http://www.grimes.demon.co.uk/workshops/fusWSNine.htm
| |
| | Richard
| | --
| | http://www.grimes.demon.co.uk/workshops/fusionWS.htm
| | http://www.grimes.demon.co.uk/workshops/securityWS.htm
| |
| |
| |
|
|
 
S

Steven Cheng[MSFT]

Thanks for your followup Gary,

Anyway, glad that it has been working for you. If there're anything else we
can help, please feel free to post here.

Regards,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)

--------------------
| From: "Gary" <[email protected]>
| References: <#[email protected]>
<[email protected]>
<[email protected]>
<[email protected]>
| Subject: Re: Resource access and culture info
| Date: Thu, 1 Dec 2005 10:46:05 -0000
| Lines: 212
| X-Priority: 3
| X-MSMail-Priority: Normal
| X-Newsreader: Microsoft Outlook Express 6.00.2900.2180
| X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.2180
| X-RFC2646: Format=Flowed; Original
| Message-ID: <[email protected]>
| Newsgroups: microsoft.public.dotnet.framework
| NNTP-Posting-Host: 193.41.152.116
| Path: TK2MSFTNGXA02.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFTNGP11.phx.gbl
| Xref: TK2MSFTNGXA02.phx.gbl microsoft.public.dotnet.framework:104514
| X-Tomcat-NG: microsoft.public.dotnet.framework
|
| Hi Steven,
|
| It was purely not including the namespace.
|
| Once I used 'GlobalTest.strings' instead of just 'strings' it worked fine.
|
| Running through the documentation this was not clear, maybe I missed
| something or the wording is not clear regarding the use of namespaces as
I
| imagined passing the Assembly as a parameter would have meant I was using
| resources from that namespace. Documentation used -
|
|
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpguide/htm
l/cpconLocalizingResources.asp
|
| As for using a fallback namespace yes I agree but this was just a test
| application for making a localizable application.
|
|
|
| Thanks,
|
| Gary
|
|
|
|
| | > Hi Gary,
| >
| > How are you doing on this issue? Does the suggestions in my last reply
| > helps a little? If there're anything else we can help, please feel free
to
| > post here.
| >
| > Thanks & Regards,
| >
| > Steven Cheng
| > Microsoft Online Support
| >
| > Get Secure! www.microsoft.com/security
| > (This posting is provided "AS IS", with no warranties, and confers no
| > rights.)
| > --------------------
| > | X-Tomcat-ID: 51353266
| > | References: <#[email protected]>
| > <[email protected]>
| > | MIME-Version: 1.0
| > | Content-Type: text/plain
| > | Content-Transfer-Encoding: 7bit
| > | From: (e-mail address removed) (Steven Cheng[MSFT])
| > | Organization: Microsoft
| > | Date: Mon, 28 Nov 2005 03:22:30 GMT
| > | Subject: Re: Resource access and culture info
| > | X-Tomcat-NG: microsoft.public.dotnet.framework
| > | Message-ID: <[email protected]>
| > | Newsgroups: microsoft.public.dotnet.framework
| > | Lines: 132
| > | Path: TK2MSFTNGXA02.phx.gbl
| > | Xref: TK2MSFTNGXA02.phx.gbl microsoft.public.dotnet.framework:104249
| > | NNTP-Posting-Host: tomcatimport2.phx.gbl 10.201.218.182
| > |
| > | Thanks for Richard's infomative inputs.
| > |
| > | Hi Gary,
| > |
| > | Actually the globalization architecture in .NET 2.0 dosn't differ much
| > | (from underlying fundatmental perspective....) from .NET 1.x...). As
| > for
| > | loading the resource file in our winform application through
| > | ResourceManager class, one thing we need to pay attention is that the
| > | "resource name" we passed in the ResourceManager's constructor is
| > namespace
| > | sensitive. So suppose our winform application's default namespace is
| > | "GlobalApp", and we put a resx file named "mystrings.xx-XX.resx" in
the
| > | project, when we try loading in the code, we should use the following
| > means:
| > |
| > | =================
| > | private void btnGetString_Click(object sender, EventArgs e)
| > | {
| > | CultureInfo ci = new CultureInfo("zh-CN");
| > | ResourceManager rm = new
| > ResourceManager("GlobalApp.mystrings",
| > | this.GetType().Assembly);
| > | string hw = rm.GetString("HELLOWORLD",ci);
| > |
| > | MessageBox.Show(hw);
| > | }
| > | =================
| > |
| > | notice that the resource file name is "GlobalApp.mystrings" rather
than
| > | "mystrings" since namespace is also required....
| > |
| > | In addition, I strongly agree with Richard's opinion on providing a
| > default
| > | netural resource file at the very beginning (before we add other
culture
| > | specific resource files.....). This can help our application always
get
| > a
| > | default fallback resource when can not find a certain specifc
culture's
| > | resource.....
| > |
| > | Thanks,
| > |
| > | Steven Cheng
| > | Microsoft Online Support
| > |
| > | Get Secure! www.microsoft.com/security
| > | (This posting is provided "AS IS", with no warranties, and confers no
| > | rights.)
| > |
| > |
| > |
| > | --------------------
| > | | From: "Richard Grimes" <[email protected]>
| > | | References: <#[email protected]>
| > | | Subject: Re: Resource access and culture info
| > | | Date: Fri, 25 Nov 2005 22:20:31 -0000
| > | | Lines: 73
| > | | X-Priority: 3
| > | | X-MSMail-Priority: Normal
| > | | X-Newsreader: Microsoft Outlook Express 6.00.2900.2527
| > | | X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.2527
| > | | X-RFC2646: Format=Flowed; Response
| > | | Message-ID: <[email protected]>
| > | | Newsgroups: microsoft.public.dotnet.framework
| > | | NNTP-Posting-Host: grimes.gotadsl.co.uk 62.3.255.233
| > | | Path:
TK2MSFTNGXA02.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFTNGP15.phx.gbl
| > | | Xref: TK2MSFTNGXA02.phx.gbl microsoft.public.dotnet.framework:104195
| > | | X-Tomcat-NG: microsoft.public.dotnet.framework
| > | |
| > | | Gary wrote:
| > | | > am having some trouble accessing culture specific resources using
| > | | > Vs.Net 2005, what process have I missed?
| > | | >
| > | | >
| > | | > * Created a Windows Forms Application called GlobalTest
| > | | > * Created the following code in button1_Click :
| > | | >
| > | | > ResourceManager rm = new ResourceManager("strings",
| > | | > this.GetType().Assembly);
| > | | > CultureInfo ci = new CultureInfo("en-US");
| > | |
| > | | Is there a reason why you explicitly set the culture? If you do not
do
| > | | this the ResourceManager class will get the culture from the
machine,
| > | | which is usually the best thing to do.
| > | |
| > | | > MessageBox.Show(rm.GetString("test", ci));
| > | | >
| > | | > * Added a file called 'strings.en-US.resx' to my project and
created
| > a
| > | | > string entry with the name 'test' and a value of 'hello world'.
| > | |
| > | | Is this an XML file? It should be. You can have non XML resources,
in
| > | | which case they are string files with lines in the format name=value
| > | |
| > | | You must compile the .resx
| > | |
| > | | > Created a key.snk using sn -k key.snk at the VS2005 command
prompt
| > and
| > | | > signed my Windows Application with it.
| > | |
| > | | Why? There are few reasons to sign an application.
| > | |
| > | | > VS.NET 2005 builds the application and satellite assembly with the
| > | | > following parameters -
| > | |
| > | | You don't seem to have a line for resgen.
| > | |
| > | | > System.Resources.MissingManifestResourceException: Could not find
| > any
| > | | > resources appropriate for the specified culture or the neutral
| > | | > culture. Make sure "strings.resources" was correctly embedded or
| > | | > linked into assembly "GlobalTest" at compile time, or that all the
| > | | > satellite assemblies required are loadable and fully signed.
| > | |
| > | | This tells you a lot. You have two resources in the main assembly:
| > | |
| > | | GlobalTest.Form1.resources
| > | | GlobalTest.Properties.Resources.resources
| > | |
| > | | and the satellite has one resource
| > | |
| > | | GlobalTest.strings.en-US.resources
| > | |
| > | | The first error is that the main assembly should have the *neutral*
| > | | resource called GlobalTest.strings.resources so that if the
requested
| > | | localized resource cannot be found the ResourceManager will fall
back
| > to
| > | | the neutral resource. This is the convention.
| > | |
| > | | Also, check the that the resource requested when you create the
| > | | ResourceManager is the same name as in the main assembly and the
| > | | satellite (taking the localisation into account, but omitting the
| > | | .resources part). Since the satellite has a resource called
| > | | GlobalTest.strings.en-US.resources the parameter to ResourceManager
| > | | should be GlobalTest.strings.
| > | |
| > | | More details can be found in my Fusion workshop:
| > | |
| > | | http://www.grimes.demon.co.uk/workshops/fusWSNine.htm
| > | |
| > | | Richard
| > | | --
| > | | http://www.grimes.demon.co.uk/workshops/fusionWS.htm
| > | | http://www.grimes.demon.co.uk/workshops/securityWS.htm
| > | |
| > | |
| > | |
| > |
| > |
| >
|
|
|
 

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