Monday, August 27, 2007

Satellite Assemblies

Creating Satellite Assembly

Satellite Assemblies are used to store local resources.To create satellite assembly from the .resx file, following steps are taken.

1. Use Resgen.exe utility to generate resource file from .resx file
2. Use Al.exe to generate satellite assembly

For Example
Suppose you have resource file that stores resource in German language.

1. Resgen.exe

Note - Though its not necessary to give .resources file name but its recommanded to give it prefixed with namespace.

2. Al.exe /t:lib / /culture:de /out:MyApp.German.dll

Note - For including multiple resource file in a single satellite assembly, you can use /embed: option multiple times in the command like...

Al.exe /t:lib / / /culture:de /out:MyApp.German.dll

Using Satellite Assembly

ResourceManager class in .net can be used to access resources in the satellite assembly.

Example: following is the page load event handler of login.aspx page.

protected void Page_Load(object sender, EventArgs e)
static ResourceManager _resourceManager;string Str = Server.MapPath("bin/MyApp.German.dll");
_resourceManager = new ResourceManager("", Assembly.LoadFrom(Str));
Page.Culture =CultureInfo.CreateSpecificCulture("de").Name;
Page.UICulture = CultureInfo.CreateSpecificCulture("de").Name;
lblUserName.Text = ResManager.GetString("UserName");
lblPassword.Text = ResManager.GetString("Password");
btnSubmit.Text = ResManager.GetString("Login");

Note - The first parameter of the ResourceManager class constructor is the base name of the resource that the satellite assembly contains, which is the qualified name of the .resources file from which satellite assembly is created using Al.exe


Anonymous said...

hi this is harika......
i had completed all the application following ur steps but i couldn't understand what is ResManager in ur sample code plz help me

galvin said...

this is the problem with copy and paste,,,, people cannot understand.........

sanjay saini said...

Hi, replace ResManager object with _resourceManager to solve the confusion. Actually ResManager is an object of a class derived from ResourceManager class but I kept it out of this post to make it short...I just wanted to give an idea about using Satellite Assemblies in the code.

v.Chauhan said...

Thanks Sanjay you save my life
I search all over but not found that first i need to create the resource file from the .resx file then Use the Al.exe to make satellite assmbly.