Creating and Implementing Satellite Assemblies
If you plan on localising your application (making your application customisable for different languages and cultures) you should use satellite assemblies and neutral code.
- Getting Started with Visual Studio
- Using the Visual Studio Integrated Development Environment
- Using the Visual Studio Debugger
- XML Documentation in Visual Studio
- Using Microsoft .Net Command Line Tools
- What is an Assembly in Microsoft .Net?
- Creating and Using a .NET Assembly in C#
- Creating and Implementing Satellite Assemblies
- Creating Strong Named Assemblies in Microsoft .Net
- Visual Studio Task List
- Resources and Localisation in C# Projects
- Localising Microsoft .Net Applications with C#
- Using Resource Files in C# Applications
- Using XSD Tool to Generate Classes from XML
- 10 Visual Studio Tools You May Not Know About
Adverts Blocked Please disable AdBlocking software and allow me to set cookies so that I can continue providing free content and services.
Neutral code does not contain any hard coding or language/culture specific code. For example, there is no hardcoded strings or symbols, no hard coded date formatting and no region specific calculations e.g. VAT.
When creating a satellite assembly you should work with the naming convention suggested by Microsoft, The format of which is
where the culture identifier consists of ISO language and culture strings. You can find a list of culture codes in this list List of .Net Culture Codes.
Satellite assemblies use a hub and spoke design, with your neutral code at the centre (hub) and various culture-specific satellite assemblies plugging into it (spokes). As a result, the runtime requires that you place resources in specific locations so that they can be easily located and used. If you do not compile and name resources as expected, or if you do not place them in the correct locations, the common language runtime will not be able to locate them. The compiler will first look in the global assembly cache for any localised satellite assemblies if it does not find any it will look in the following locations:
- The global assembly cache for an assembly matching the requested culture for the application
- The directory of the currently executing assembly for a directory matching the requested culture.
- The global assembly cache again, this time for the parent assembly of the requested resource.
- The runtime next checks the directory of the currently executing assembly to see if it contains a parent directory. If a parent directory exists, the runtime searches the directory for a valid satellite assembly for the parent culture.
- The runtime next searches parent assemblies, as in the previous step, through many potential levels.
- If a resource is not found then the default culture is used.
Creating Satellite Assemblies
By definition, satellite assemblies can only contain resources. They cannot contain any executable code. Satellite assemblies are compiled from resource files which can be added to a project from the add new item menu.
Resource files can be directly compiled into the executable, however, for the purposes of scalability, a satellite assembly allows new cultures and languages to be added without recompilation or distribution. Satellite assemblies can be used so that client downloads and installs a common executable and the just downloads and installs one satellite assembly for their location.
Satellite assemblies are created using the Assembly Linker (al.exe) command line tool.
Use the following command to create a satellite assembly for the application TestApp from the file strings.ja-JP.resources
static ResourceManager rm = new ResourceManager("strings", Assembly.GetExecutingAssembly());
This line of code will load the strings resource file from the assembly created above, assuming that ja-JP is the current system locale.
You can access or modify the current culture using the CultureInfo class:
CultureInfo ci = Thread.CurrentThread.CurrentCulture; Thread.CurrentThread.CurrentUICulture = en.US;
Last updated on: Thursday 22nd June 2017