0

I want to get resource key values from resource file specified culture info. Here is the code;

CultureInfo languageInfo = CultureInfo.CurrentUICulture;
ResourceSet rset = myresourceClass.ResourceManager.GetResourceSet(languageInfo, true, false);

Third parameter of GetResourceSet is false because if it's true, it loads the default resource file. I want the specified one. But if so it returns null. Why this is so?

Ondrej Janacek
  • 12,486
  • 14
  • 59
  • 93
Serhat Koroglu
  • 1,263
  • 4
  • 19
  • 41
  • What is the current UI culture? Do you have a matching resource file? – Szymon Nov 25 '13 at 10:11
  • I didn't need to specify this; yes have the required resource file like myresourceClass.en.resx, and current ui is 'en'. – Serhat Koroglu Nov 25 '13 at 10:14
  • "If the resources have not been localized for that culture and tryParents is true, GetResourceSet uses resource fallback rules to load an appropriate resource. If tryParents is false and a culture-specific resource set cannot be found, the method returns null." Clearly states you do not have the culture specific resource file. Check where you are actually executing the code that the resource file is also there. – Janne Matikainen Nov 25 '13 at 10:28
  • that's a class library project and project dll files were copied into en directory as resource lib dll. Do you have any advice? I adjusted "copy to output" property to copy always. – Serhat Koroglu Nov 25 '13 at 11:55
  • @JanneMatikainen ok now it works, I hadn't copied the resource dll output for my class library. Do I need this really? Shouldn't class library build contain these resource files? – Serhat Koroglu Nov 25 '13 at 12:39

1 Answers1

1

Assuming you have a class library like "MyNamespace.Resources" in which you have your resx files and generated designer files and you have another class library "MyNamespace.ClassLibrary" which is referring the resources. The resx files should Build Action should be set to "Embedded resource".

You need to sure that the "MyNamespace.Resources" reference in "MyNamespace.ClassLibrary" has the property "Copy to Local" set to True so the resoruce dll is copied on build.

If you are accessing resx files directly with the resource manager then you need to have the resx files.

Janne Matikainen
  • 5,061
  • 15
  • 21