Search code examples
c#winformssatellite-assembly

How to get location of current culture's satellite assembly?


My C#/WF application uses some files, which are different for different languages. These file can not be placed as resources in satellite assemblies. I wish however to put them in the same directories as the satellite assemblies reside, but I need to know actually where the assembly resides (including the situation, when default language embedded in the binary file is used).

For example, when application switches automatically to polish language, I wish to retreive location:

D:\<app folder>\pl-PL\

Is there a way to do so? Please note, that I wish to retreive this information from the assembly and not by guessing the folder location.


With help of Steve B, here's a solution:

string FindSatelliteAssemblyLocation(CultureInfo culture)
{
    if (culture == CultureInfo.InvariantCulture)
        return Path.GetDirectoryName(Application.ExecutablePath);

    try
    {
        Uri location = new Uri(Assembly.GetExecutingAssembly().GetSatelliteAssembly(culture).CodeBase);
        return Path.GetDirectoryName(location.LocalPath);
    }
    catch
    {
        return FindSatelliteAssemblyLocation(culture.Parent);
    }
}

Solution

  • You may use the current thread UI culture to get the language :

    var subfolder = System.Threading.Thread.CurrentUICulture.Name;