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

  • Live Event Date: December 11, 2014 @ 1:00 p.m. ET / 10:00 a.m. PT Market pressures to move more quickly and develop innovative applications are forcing organizations to rethink how they develop and release applications. The combination of public clouds and physical back-end infrastructures are a means to get applications out faster. However, these hybrid solutions complicate DevOps adoption, with application delivery pipelines that span across complex hybrid cloud and non-cloud environments. Check out this …

  • Some of the statistics about the growth of enterprise mobility are surprising, not the least of which is the 4X increase in mobile malware from 2013 to 2014. Many employees today not only expect to be able to use their own personal devices at work, but will even contravene policies that restrict personal device use for work.  IT must find the right approach that balances the benefits of mobility with the risks involved.  This on-demand webcast offers steps toward developing a winning mobile strategy, and …

Most Popular Programming Stories

More for Developers

RSS Feeds