App_GlobalResources & Resources namespace

C

CuriousGeorge

I've upgraded a .Net 1.1 web app to 2.0 and am having a heck of a time
getting resources to work again. From what I understand if I move my
strings.resx file into the App_GlobalResources folder I should magically be
able to reference my strings using the syntax Resources.strings.string1.
This isn't working for me. Is there something I'm missing other than moving
the file itself and rebuilding? I get this error:

"The type or namespace name 'strings' does not exist in the namespace
'System.Resources' (are you missing an assembly reference?)"

-Brett-
 
W

Wei-Dong XU [MSFT]

Hi,

Thanks for posting at the newsgroup!

ASP.net 2.0 has introduced one code compilation model, very different from
the ASP.net 1.1. For the resource management, ASP.net 2.0 will generate one
namespace Resources for the resources located under the folder
"App_GlobalResources". For each resource (string, image etc) at the
resource file, ASP.net will dynamically generate the static property for
each.

For example, we can add one Resource.resx file at the web application
project located under App_GlobalResources. Then we define one string called
"MySiteTitle" at the resoruce designer. Then we can write the code below to
access this string resource:
String mysitename = Resources.Resource.MySiteTitle;

The Resources namespace is dynamically generated by ASP.net 2.0. And the
second part of the resource name is the resx file name. If we chnage the
resource name to HappyANiceDayResource.resx, ASP.net 2.0 will dynamically
the correspond name and we can access the string resource as below:
String mysitename = Resources.HappyANiceDayResource.MySiteTitle;

This design will be quite easy for us to locate the resource. For your
application migrated from ASP.net 1.1, I'd suggest please change the code
to locate the resources.

In addition, I'd suggest please this article will be of great help for you
to migrate the application from ASP.net 1.1 to ASP.net 2.0:
ASP.NET 2.0 Migration Overview
http://msdn2.microsoft.com/en-us/library/ms227549.aspx

Please feel free to let me know if you have any further question on this
issue.

Have a nice day!

Best Regards,
Wei-Dong XU
Microsoft Support
 
C

CuriousGeorge

I appreciate the effort to help me here, but frankly if you'd read my post
you'd see I am aware of how this is supposed to work. I'm saying it is not
working for me. I'm looking for a little assistance on what I might be
doing wrong. Let me give a little more detail.

When VS05 converted my ASP.Net 1.1 app to 2.0 it created the
App_GlobalResources folder and moved my one string resource (resx) file into
it. For some reason I was unable to open the resx file in the designer so I
went ahead and created a new one and copied all of my strings into it (then
deleted the original). My resx file is named strings.en.resx and is located
in the App_GlobalResources subfolder.

In my code-behind file if I try to use the syntax:
Resources.strings.en.mystring I am getting compilation errors stating
'Resources' does not exist in the current context.

So is there something I'm missing here? VS05 does not appear to be creating
the typed dataset for my string file.

-Brett-

"Wei-Dong XU [MSFT]" said:
Hi,

Thanks for posting at the newsgroup!

ASP.net 2.0 has introduced one code compilation model, very different from
the ASP.net 1.1. For the resource management, ASP.net 2.0 will generate
one
namespace Resources for the resources located under the folder
"App_GlobalResources". For each resource (string, image etc) at the
resource file, ASP.net will dynamically generate the static property for
each.

For example, we can add one Resource.resx file at the web application
project located under App_GlobalResources. Then we define one string
called
"MySiteTitle" at the resoruce designer. Then we can write the code below
to
access this string resource:
String mysitename = Resources.Resource.MySiteTitle;

The Resources namespace is dynamically generated by ASP.net 2.0. And the
second part of the resource name is the resx file name. If we chnage the
resource name to HappyANiceDayResource.resx, ASP.net 2.0 will dynamically
the correspond name and we can access the string resource as below:
String mysitename = Resources.HappyANiceDayResource.MySiteTitle;

This design will be quite easy for us to locate the resource. For your
application migrated from ASP.net 1.1, I'd suggest please change the code
to locate the resources.

In addition, I'd suggest please this article will be of great help for you
to migrate the application from ASP.net 1.1 to ASP.net 2.0:
ASP.NET 2.0 Migration Overview
http://msdn2.microsoft.com/en-us/library/ms227549.aspx

Please feel free to let me know if you have any further question on this
issue.

Have a nice day!

Best Regards,
Wei-Dong XU
Microsoft Support
 
S

Steven Cheng[MSFT]

Hi Brett,

As for the ASP.NET 2.0 localization and resource handling, it hasn't change
much from the original one. For the resource file, e.g .resx or .txt file,
their file name should not contain any cultureInfo name(such as "en",
"fr-Fr", this is used for the runtime to idenitity them as the same
resource for a specific language/culture.

For example, if we have the following resource files:

MyResources.strings.resx

MyResources.strings.en.resx

MyResources.strings.fr.resx


They're actually a single resource item, just of different
culture/language. At runtime in the code, we just use the following
statement to retrieve value from the above resource file:


Response.Write(Resources.MyResources.strings.XXXXX)

(no prefix like "en" or "fr" or....)

and which file to use depend on the current thread's UICulture.

For example, if we add the following code to manually set the thread's
CurrentUICulture:

============
protected void Page_Load(object sender, EventArgs e)
{

System.Threading.Thread.CurrentThread.CurrentUICulture = new
System.Globalization.CultureInfo("fr-FR");

Response.Write(Resources.MyResources.strings.XXXXX)

============

the above code will read the resource string from the
MyResource.strings.fr.resx file.

You can also get some further description in the MSDN document on ASP.NET
global/localization:


#ASP.NET Globalization and Localization
http://msdn2.microsoft.com/en-us/library/c6zyy3s9.aspx

#Walkthrough: Using Resources for Localization with ASP.NET
http://msdn2.microsoft.com/en-us/library/fw69ke6f.aspx

Hope all these help you.


Regards,

Steven Cheng
Microsoft Online Community Support


==================================================

When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.

==================================================


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

CuriousGeorge

It turns out my problem came down to the fact that my resource file was
named simply 'strings.en.resx'. For some reason Visual Studio doesn't deal
with that as documented (in generating the typesafe dataset). If I change
the name to something like MyResources.string.en.resx then everything works
as documented.

This was just one of those crazy bang your head against the wall kindof
problems. I was doing everything as documented but apparently chose a name
that either has special meaning or is involved in a bug of some sort.

Thanks for the help...

-Brett-
 
S

Steven Cheng[MSFT]

Thanks for your followup Brett,

Yes, I admit that the document still need much improvement since it lacks
good and complete samples or explanation on some common scenario. Anyway,
if you meet any problem, please feel free to post here, we will be happy to
be of assistance.

Regards,

Steven Cheng
Microsoft Online Community Support


==================================================

When responding to posts, please "Reply to Group" via your newsreader so
that others may

learn and benefit from your issue.

==================================================


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

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

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,482
Members
44,901
Latest member
Noble71S45

Latest Threads

Top