Last post Feb 08, 2008 03:43 AM by rstrahl
Feb 06, 2008 10:32 AM|Broodmdh|LINK
I am trying to convert my ASP .NET 1.1 (VB) app to 2.0, but I'm having a lot of trouble with the resource files. I placed them in the App_LocalResources folder (maintaining the sub-folder structure that we
already had in place), and I am using the following code to try and access them:
Dim gStr As ResourceManager
gStr = New ResourceManager("LSI." & newPageName, [Assembly].GetExecutingAssembly)
This doesn't return anything (just an empty string).
I've also tried the following:
ctrl1.Text = Me.GetLocalResourceObject("PageTitle").ToString()
This, unfortunately, doesn't work and throws the following error:
"The resource class for this page was not found. Please check if the resource file exists and try again.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code."
The resource files have a build action of "Content", and not "Embedded Resource", but I don't know if this is right. I've tweaked everything so many times I don't know what else to do. I've also tried using gStr.GetString("PageTitle", ci), but that just throws
a "Could not find any resources appropriate for the specified culture or the neutral culture" error.
I've read that the resource files have to be at the same level as the page they are related to, but that hasn't worked for me either. I'm setting all of this in a base class that is inherited by all the pages in the app, and I don't know if that makes a difference.
This whole process is very frustrating, especially because I am operating on a very tight timeframe. Any help would be appreciated.
Feb 08, 2008 03:43 AM|rstrahl|LINK
How are your resource files named?
If you have existing 1.x resource you'll want to use Global Resources, not Local resources. Local Resources follow a specific naming patter, both for the filename (same as the page plus locale plus resx) and the resource keys (controlId.Property).
Global Resources act like you'd expect 1.1 resources to act.
To retrieve global resources use HttpContext.GetGlobalResourceObject("resxFilenameWithoutResxExtension","ResourceKey").
Note this doesn't use a ResourceManager, but rather the ASP.NET ResourceProvider which is optimized for serving resources in ASP.NET. Generally it's a better idea to go that route. You should be able to get the 'old' behavior you're expecting just using
This article might help:
especially in the second part regarding Resource Based Localization.
Hope this helps,
+++ Rick ---