Satellite Assemblies

While looking for the use of satellite assemblies, I came across many examples. But, when I tried to run them, most of them did not fulfill my expectations from a satellite assembly.

In this article, you'll see what satellite assemblies are, how to create them, and how to use satellite assemblies with strong named assemblies with very simple and small pieces of code chunks.

What Is a Satellite Assembly?

A definition from MSDN says something like this: "A .NET Framework assembly containing resources specific to a given language. Using satellite assemblies, you can place the resources for different languages in different assemblies, and the correct assembly is loaded into memory only if the user elects to view the application in that language."

This means that you develop your application in a default language and add flexibility to react with change in the locale. Say, for example, you developed your application in an en-US locale. Now, your application has multilingual support. When you deploy your code in, say, India, you want to show labels, messages shown in the national language which is other than English.

Satellite assemblies give this flexibility. You create any simple text file with translated strings, create resources, and put them into the bin\debug folder. That's it. The next time, your code will read the CurrentCulture property of the current thread and accordingly load the appropriate resource.

This is called the hub and spoke model. It requires that you place resources in specific locations so that they can be located and used easily. 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. As a result, the runtime uses the default resource set.

Creating a Satellite Assembly

  1. Create a folder with a specific culture name (for example, en-US) in the application's bin\debug folder.
  2. Create a .resx file in that folder. Place all translated strings into it.
  3. Create a .resources file by using the following command from the .NET command prompt. (localizationsample is the name of the application namespace. If your application uses a nested namespace structure like MyApp.YourApp.MyName.YourName as the type of namespace, just use the uppermost namespace for creating resources files—MyApp.)
  4. resgen Strings.en-US.resx LocalizationSample.
       Strings.en-US.resources
    al /embed:LocalizationSample.Strings.en-US.resources
       /out:LocalizationSample.resources.dll /c:en-US
    

    The above step will create two files, LocalizationSample.Strings.en-US.resources and LocalizationSample.resources.dll. Here, LocalizationSample is the name space of the application.

  5. In the code, find the user's language; for example, en-US. This is culture specific.
  6. Give the assembly name as the name of .resx file. In this case, it is Strings.

Using a Satellite Assembly

Follow these steps:

Thread.CurrentThread.CurrentCulture =
   CultureInfo.CreateSpecificCulture(specCult);
Thread.CurrentThread.CurrentUICulture =
   new CultureInfo(specCult);
ResourceManager resMgr =
   new ResourceManager(typeof(Form1).Namespace + "." +
                       asmName, this.GetType().Assembly);
btnTest.Text = resMgr.GetString("Jayant");

That's it. See how simple is it to create a satellite assembly and use it in your code.

Here's how to use a satellite assembly if your assembly is a strong named assembly. When you create an assembly with a string name, all the assemblies it refers to must have a strong name. This is true with a satellite assembly also. Here are the steps to create a strong named satellite assembly.

String Naming a Satellite Assembly

al /embed:ExploreDotNet2005.Strings.en-US.resources
   /out:ExploreDotNet2005.resources.dll /c:en-US
   /template:../ExploreDotNet2005.exe /keyfile:../../..
   /KeyPair.snk

Remember that /template is very important because it inherits the parent assembly manifest, and the strong name key pair must be the same as that for the running assembly. I've tried using different strong names for satellite assembly and executing the assembly. but it throws an exception.

That's it, friends. In case of any queries, let me know.



About the Author

Jayant Kulkarni

Dear Friends, I'm from Pune and curently working with Symantec Corp. I'm having more than 7 years of exp in software field and have worked on areas like ASP.NET, C#, .NET remoting, web services, pocket pc applciations. I'm a brainbench certified software engineer in .NET framework, C#, ADO.NET and ASP.NET. If you like any of my articles or you want to suggest some changes and improve the way I code, write articles feel free to mail me at: jayantdotnet@gmail.com

Downloads

Comments

  • LSACreator

    Posted by Adam on 02/14/2013 03:33pm

    I found tool that could be useful when working with satellite assemblies. Link below. :) www.tbs-apps.com/lsacreator

    Reply
Leave a Comment
  • Your email address will not be published. All fields are required.

Top White Papers and Webcasts

  • Hybrid cloud platforms need to think in terms of sweet spots when it comes to application platform interface (API) integration. Cloud Velocity has taken a unique approach to tight integration with the API sweet spot; enough to support the agility of physical and virtual apps, including multi-tier environments and databases, while reducing capital and operating costs. Read this case study to learn how a global-level Fortune 1000 company was able to deploy an entire 6+ TB Oracle eCommerce stack in Amazon Web …

  • Managing your company's financials is the backbone of your business and is vital to the long-term health and viability of your company. To continue applying the necessary financial rigor to support rapid growth, the accounting department needs the right tools to most efficiently do their job. Read this white paper to understand the 10 essentials of a complete financial management system and how the right solution can help you keep up with the rapidly changing business world.

Most Popular Programming Stories

More for Developers

Latest Developer Headlines

RSS Feeds