Last post Feb 23, 2006 10:06 PM by NHuffman
Feb 18, 2006 05:32 PM|roachslayer|LINK
I have spent hours reading up on the 2.0 way of localization, and experimenting in my web app, and cannot for the life of me get any of this working at ANY level. Please help!
Assume that inside Main.resx and Test1.resx I have an item named "Hello.Text" with the value "Hello World"
Now, in my Test1.aspx page ALL of these methods do not work. I get a
null reference exception:
Label1.Text = this.GetLocalResourceObject("Hello.Text").ToString();
Label1.Text = this.GetGlobalResourceObject("Main", "Hello.Text").ToString();
Strong Type: How do you use it? Where the heck is it? This is not possible whatsoever from within my page:
Intellisense shows me nothing. Nothing is available or accessible. "Resources" is not available in the page class... how is this all mapped?
This is all so completely broken and frustrating. I have followed instructions on how to do this with extensive attention to detail using many different excellent reference guides. My browser is on the correct
default language. Am I missing some stupid thing, or is my .NET framework or Visual Studio just completely freaking hosed? This should not be so difficult. It's acting as if my resx files dont exist, even though they do.
Feb 19, 2006 01:47 AM|jcasp|LINK
Feb 19, 2006 07:55 PM|rmprimo|LINK
Intellisense shows me nothing
Did you build the project first? Sometimes it won't do it automatically but will prompt you in the warnings list to generate the resource class by just clicking on it. Intellisense draws the schema from the code generated
class. The other reason is if the files are in the wrong place, especially outside the special folder.
null reference exception
Assume that inside Main.resx and Test1.resx I have an item named "Hello.Text"
It looks like you are testing local resources with Test1.aspx, and there is a control(is it a label?) with a property Text . You need to run the
Generate Local Resources utility to create the meta tags in the control on the page and it also copies the literal to the resx. From that point on, the value that is in the page markup is ignored. You can even remove the text from the page
AFTER running the GLR.
Now, you have it a bit muddled in the global resource. You are not allowed dots in the global key.(actually you are but it delimits a nested namespace) Try it simpler first with no namespaces Name the key
Also, the code generated class is in the Temp aspnet folder
C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\Temporary ASP.NET Files
It is a cryptically named file with an extension .cs You can find it with some ingenuity by searching for
Hello_Text literal It has to be outside the project until it is compiled. The first thing you will see is that it is not in the System namespace, just
So that is the issue with
string foo = System.Resources.Main.Hello;
if you had compiled properly you should have gotten something like this:
string foo = Resources.Main.Hello.Text
Note that the IDE assumed that the resource name is Text and that Hello was just a namespace nested inside the Main class which itself is inside the Resources
If you tried with a simple key it should work easier:
string foo = Resources.Main.Hello_Text;
string foo =
likewise with the inline expression.
If you do these samples(they all work) you will have a good idea.
If you are still having problems, zip your test project (errors and all) and email it to me.
Feb 20, 2006 06:57 PM|roachslayer|LINK
Thanks for the response. Excellent info. Here is my status now:
I removed the.Text from the resource, so I now have Hello_Text to make it simple. I did make sure to compile. I checked the Temporary ASP.NET folder for files containing my "Hello_Text" and found nothing. And my intellisense has no "Resources" namespace
whatsoever, not even the root itself. If I begin to Type "Reso" in say the Page_Load funtion, Intellisnse gives me only the following items with the word "resource" in them as show below.
...but no "Resource" namespace. I cannot even begin to access global resources this way.
and I have tried all the samples at
and none of them work, even if I copy/paste the exact code. I get null reference, and/or cannot compile because there is no such thing as "Resources" namespace at the page level.
However, when I built a test project with nothing but the code from the quickstart samples, everything worked fine. the Resources Namespace showed up, and everything worked. But none of this works in my other project I am trying to add
It is a DotNetNuke 4.0.2 project. And what I noticed is that it violates a lot of the rules for .NET 2.0 localization because it was a crappy port from 1.1. Sooo..... I think I am screwed. I think what is happening is even if I structure my resources properly,
it wont compile them because of other errors elsewhere, and I end up getting no Resources Namespace generated, and cannot even use local resources for whatever reason. I suppose I am stuck untill the DNN team cleans up the .NET 2.0 version of DNN.
Feb 20, 2006 07:05 PM|roachslayer|LINK
On a slight tangent from all this...
ASP.NET projects have this cool localization stuff. But how can one use String Typed Localization in a .NET 2.0 Class Library?
I created a class library called ClassLbrary1 and I added properly structured resources into it with an App_GlobalResources folder. I compile it, but I get no Resources namespace. nor do I have access to things like GetGlobalResourceObject. Is there
a way to do this, using similar "cool tools" found in ASP.NET? Or do I have to use the old method of building a resource manager?
Feb 20, 2006 07:38 PM|jcasp|LINK
Feb 20, 2006 07:49 PM|rmprimo|LINK
I am not a huge fan of DNN. I have heard that Rainbow pride themselves in localization, but have never worked with it.
Anyway, v2.0 offers out of the box tons of goodies and you don't have to depend on other frameworks to get their act together.
Feb 20, 2006 08:31 PM|rmprimo|LINK
It is not a project thing. It is an application thing.
GetGlobalResourceObject(...) is a static member of the HttpContext object of a web app. It is just exposed for convenience in the page class(oops kitchen sink class). But you can always use it in a non-strongly typed manner in your lib.
The auto-generation is only for the application. It not only generates the code; based on the file name inside the special folder it also generates the satellite assemblies for you.
You can always add the global resx to App_GlobalResources along with referencing the lib, a bit of an extra step but not too bad. This is where that namespace thing (which is BTW totally undocumented and confusing to figure out) would come
Feb 23, 2006 10:06 PM|NHuffman|LINK
This is a short video that introduces the new resources model in ASP.NET 2.0; touching on App_LocalResources and App_GlobalResources.
Hope this helps