GetResourceSet does not load fallback values

c#, resources

Solution

You have to get all keys from the invariant culture and then you can lookup all translation. So the fallback works.

The looked-up resources can be stored in a dictionary.

var keys = Resources.ResourceManager
    .GetResourceSet(CultureInfo.InvariantCulture, true, true)
    .Cast<DictionaryEntry>()
    .Select(entry => entry.Key)
    .Cast<string>();

var deResources = keys.ToDictionary(
    key => key, 
    key => Resources.ResourceManager.GetString(key, CultureInfo.GetCultureInfo("de")));

Problem

I have two files: Resources.resx and Resources.de.resx. The Resources.de.resx contains only one translated value. I am using the following method to load all resource keys/values: ``` ResourceSet resourceSet = Resources.ResourceManager.GetResourceSet(Thread.CurrentThread.CurrentCulture, true, true); ``` When I load the resource set first time my Thread.CurrentThread.CurrentCulture.Name is empty string, Thread.CurrentThread.CurrentCulture.NativeName = "Invariant Language (Invariant Country)", Thread.CurrentThread.CurrentCulture.LCID = 127. So, the resource set has 200 keys with values loaded from Resources.resx as expected. Then I switch the current culture using the following code which is triggered by clicking a button: ``` Thread.CurrentThread.CurrentCulture = new CultureInfo("de"); Thread.CurrentThread.CurrentUICulture = Thread.CurrentThread.CurrentCulture; ``` When I load the resource set now, I have only one key in the set. It is the translated key from Resources.de.resx. But I still expect to have 200 keys with only one item translated to German (de) language. The parent culture of current German(de) culture is the same invariant language culture like it was when I call the method to fetch resource set first time. Basically, it looks like the fallback is not working for some reasons. Could you tell me what am I doing wrong?

Original source