views:

312

answers:

2

Hello, I would like to create resource manager on my page and use some data stored in my resource files. (default.aspx.resx and default.aspx.en.resx)

The code looks like this:

System.Resources.ResourceManager myResourceManager = System.Resources.ResourceManager.CreateFileBasedResourceManager("resource", 
               Server.MapPath("App_LocalResources") + Path.DirectorySeparatorChar, null);

    if (User.Identity.IsAuthenticated)
    {
        Welcome.Text =  myResourceManager.GetString("LoggedInWelcomeText");
    }
    else
    {
        Welcome.Text = myResourceManager.GetString("LoggedOutWelcomeText");
    }

but when i compile and run it on my local server i get this type of error:

Could not find any resources appropriate for the specified culture (or the neutral culture) on disk. baseName: resource locationInfo: fileName: resource.resources 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.

Exception Details: System.Resources.MissingManifestResourceException: Could not find any resources appropriate for the specified culture (or the neutral culture) on disk. baseName: resource locationInfo: fileName: resource.resources

Source Error:

Line 89: else Line 90: { Line 91: Welcome.Text = myResourceManager.GetString("LoggedOutWelcomeText"); Line 92: } Line 93:

can you please assist me with this issue?

A: 

According to MSDN, CreateFileBasedResourceManager is expecting compiled resource files. Usually, one puts .resx files in App_LocalResources. Do you have files in this directory named resource.XXX.resources (where XXX is the current culture id) in this directory.

I don't have a VS handy in order to check this in an ASP.NET project, but the usual way to handle resource strings is to go the project properties, Resources tab and create strings there. This generates a strongly-typed wrapper around your resources, avoiding the need to explicitly create your own ResourceManager.

Timores
yes, i have default.aspx.en.resx and default.aspx.resx in App_LocalResources and there is also row with name "LoggedOutWelcomeText"
Bart
OK, but the names don't start with 'resource', which is what you're telling with the call to CreateFileBasedResourceManager.
Timores
A: 

Use GetLocalResourceObject() which is part of a System.Web.Page's base. If you wish to access global resources use GetGlobalResourceObject().

keep it simple ;-)

Elementenfresser