2

Trying to access a specific localised resource file such as WebResource.en.us which is located in my App_GlobalResources folder using the following code:

string resData = GetGlobalResourceObject("WebResource.en.us", "SomeResource").ToString();

but this keeps giving me the error below:

Could not find any resources appropriate for the specified culture or the neutral culture. Make sure "Resources.WebResource.en-us.resources" was correctly embedded or linked into assembly "App_GlobalResources.bpqqrnv4" at compile time.

Any ideas ?

1 Answer 1

2

I tried the following Code

Page_Load(....)
{
   /// note - i did NOT mention the culture when accesing my resourceFiles
   Debug.WriteLineIf(
       GetGlobalResourceObject("WebResource", "someResource")!=null,
       GetGlobalResourceObject("WebResource", "someResource").ToString());

   /// accessing a culture specific resource without changing Page Culture
   CultureInfo yourCI = new CultureInfo("en-US");
   Debug.WriteLine(
      HttpContext.GetGlobalResourceObject(
          "WebResource", 
          "someResource", 
          yourCI).ToString());
}

my Page directive

<% Page Culture="en-US" UICulture="en-US" .....  %>

My App_GlobalResources folder contains two files

  • WebResource.resx
  • WebResource.en-US.resx

Using this settings and code - my Debugger printed the value without any problems. When removing WebResource.resx (my default ressource file) the same code throws an exception.

I would assume that you have to add a default resx file and remove the explicit culture notation in GetGlobalResourceObject(..., ..).

update: added some code to access specific resx culture file see also MSDN

Sign up to request clarification or add additional context in comments.

3 Comments

Yes, I have tried something similar and it does work as you say if I remove the culture notation but I need to have this as I have multiple culture resource files that I need to access.
If you need to access the resorce file of another culture,change the culture. What could be the reason for accessing a resource file of a cultur A when the current culture is B?
The reason is that I need to access a resource string that holds distributor address details for each country (which is stored in the localised resource file for that country) which needs to be accessed independently of culture selected. So even if the selected culture is UK the user may need to know distributor details for US. The answer may be to hold these details in an application level variable in web.config rather than resource files I suppose.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.