views:

94

answers:

2

Hi there

The purpose of my application is to pick some localized strings from an assembly. Part of the specification is:

  • The assembly is to be selected by the user at run-time
  • The assembly is private one, i.e. not registered with GAC

The code I came up with is:

Assembly resAssembly = Assembly.LoadFile(@"X:\PathToApp\Assembly.Name.dll");
CultureInfo ci = new CultureInfo("es-MX");
Assembly satAssembly = resAssembly.GetSatelliteAssembly(ci);

The last line threw an exception:
Could not load file or assembly "Assembly.Name.resources" or one of its dependencies. The system can not find the file specified.

I have overcome the exception by copying the folders that contain the satellite assemblies to the application root.

I do not like this approach. Any alternative ideas?

Many thanks in advance

A: 

The Assembly.LoadFile method doesn't use a binding context, so its dependencies aren't automatically found in its directory.

You can instead use Assembly.LoadFrom.

You can read Suzanne Cook's post on the differences between these two methods to obtain further information (LoadFile vs. LoadFrom).

João Angelo
A: 

I am still facing the same issue. Actually i am trying to Localize a shared COM add-in. Steps followed:

!. Created a resource file consisiting of the strings 2. Created a resource filr for the same using resgen. 3. Created Satellite assembly using AL.exe for culture en-US and placed the assembly file in the en-US folder undre bin\debug 4. Assembly assembly = Assembly.GetExecutingAssembly(); System.Globalization.CultureInfo culture = System.Globalization.CultureInfo.GetCultureInfo("en-US");
Assembly satelliteAssembly = assembly.GetSatelliteAssembly(culture); string manifestResourceName = satelliteAssembly.GetManifestResourceNames()[0]; manifestResourceName = manifestResourceName.Replace(".resources", ""); ResourceManager resourceManager = new System.Resources.ResourceManager(manifestResourceName, satelliteAssembly); string text = resourceManager.GetString("SharingOptionsGroup"); return text;

Shweta