0

I try to get the list of available Culture information, add them to a combobox and change the language on run time. My implementation acts different on different environments. There are some PCs where it works as expected, all the satellite assemblies are recognized, but on other PCs the same application does not recognize the available languages, only the default one (English).

This is my code where I try to find the available resource:

public static IEnumerable<CultureInfo> GetAvailableCultures()
    {
        List<CultureInfo> result = new List<CultureInfo>();

        ResourceManager rm = new ResourceManager(typeof(PresentationResources));

        CultureInfo[] cultures = CultureInfo.GetCultures(CultureTypes.AllCultures);
        foreach (CultureInfo culture in cultures)
        {
            try
            {
                if (culture.Equals(CultureInfo.InvariantCulture))
                {
                    continue;
                }

                ResourceSet rs = rm.GetResourceSet(culture, true, false);
                if (rs != null)
                {
                    result.Add(culture);
                }
            }
            catch (CultureNotFoundException)
            {
                //NOP
            }
        }

        return result;
    }

Also the code from the xaml from where I try to change the language:

         <ComboBox Name="LanguageComboBox"
                      SelectedIndex="{Binding SelectedLanguageIndex}"
                      ItemsSource="{Binding AvailableLanguages}"
                      DisplayMemberPath="NativeName"
                      SelectedItem="{Binding Source={x:Static lex:LocalizeDictionary.Instance}, 
                                             Path=Culture}"
                      SelectionChanged="LanguageComboBox_OnSelectionChanged">
                    </ComboBox>

I don't really understand why the exactly same application on some environments works as expected and on other ones not.

  • What are you expecting to see? Are all the cultures installed/available on the other machines? The culture list may differ from machine to machine depending on the machine config and what's installed. – Charleh Apr 16 '20 at 06:59
  • The same satellite assemblies are available on each machine. My expectation is that the application should recognize the available cultures from the build directory (for each culture I have a directory where the resource file with .resources.dll extension is found). But from your response I suppose that this is not enough, if the language are not installed on the machine, the resource file is not recognized? – brigitta torok Apr 16 '20 at 07:16
  • It should never just be one culture though it can vary, but check this related issue on SO https://stackoverflow.com/questions/25414693/c-sharp-cultureinfo-getcultures-returns-a-nearly-empty-list – Charleh Apr 16 '20 at 13:28
  • Thank you. I tried also this but it's still not working.. In my case var cultures = CultureInfo.GetCultures(CultureTypes.AllCultures); returns all the cultures, I don't have a problem with this. Seems that there are some cases when the GetResourceSet returns null. – brigitta torok Apr 17 '20 at 11:01
  • Ah so its not a culture loading issue...I guess the only other things to check are that the resources library isn't blocked (a feature of some Windows versions when copying dlls - right click and look for unblock), and to check that the user has permissions to the resource file directories. Otherwise it might be worth using process explorer to see if the satellite assemblies are loading into the app domain at all. – Charleh Apr 17 '20 at 18:55

0 Answers0