There is a library in which a method with similar code is implemented:

var rm = new ResourceManager("Reports.Resources.lang", typeof(Reports).Assembly); var dep = rm.GetString("Department", Thread.CurrentThread.CurrentCulture); 

Accordingly, the project has a resource file lang.ru-RU.resx , which is compiled into Reports.resources.dll (which I added as a link, I don’t know exactly if I need to do this).

If you connect the library directly, then when you call the method, everything works fine, the necessary resource file is taken (there are several of them), you can get access to the desired line.

But if you connect the library programmatically through Assembly.Load() , create a class object and call the same method, the resource file is not located.

The question is what to do? How to make in the second case correctly consider the resource?

  • And in what directory is the library in relation to the main program? And in what directory is the resource file. It is important. - VladD
  • The library lies in a subdirectory (let's say Data), and the resource files in Data / en-Ru, Data / en-US. - craimez
  • Yeah, that's the problem. Flip to the main directory, should take off. Or you need to replace Assembly.Load with something else, now I’ll look for sure. - VladD
  • Drop resource files into the root of the library folder or into the folder with the main problem? - craimez
  • Resources should be in theory .\ru-RU\Reports.resources.dll , etc. - VladD

1 answer 1

If you ship your assembly via Assembly.Load , dependencies are searched in the same place as for the main application, that is, in the application directory and its subdirectories of the en-US , ru-RU (for language resources). Investigation in the comments showed that your files are in the Data subdirectory, so localized resources are not located.

The simplest solution is to transfer the library to the directory with the main program, and its localization - and the subdirectories en-US , ru-RU , etc. of the program directory.

Another way is to change the configuration of the program, allowing it to find dependencies in other directories. MSDN says you need to add a section to app.config :

 <configuration> <runtime> <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1"> <!-- здесь должен быть указан ваш каталог Data --> <probing privatePath="bin;bin2\subbin;bin3"/> </assemblyBinding> </runtime> </configuration> 

A more strict path, with an indication of publicKeyToken , is described here (such a path will prevent loading anything , and only allow loading the necessary assembly):

 <configuration> <runtime> <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1"> <dependentAssembly> <assemblyIdentity name="Reports" culture="neutral" publicKeyToken="<здесь укажите токен>"/> <codeBase version="тут версия" href="FILE://тут путь"/> </dependentAssembly> </assemblyBinding> </runtime> </configuration> 

You will have to sign an assembly (as well as dependent localized assemblies!) With sn -k .

Another way described there is to subscribe to the AssemblyResolve event, and load the assembly via LoadFrom in it.


However, according to this article , LoadFrom can help LoadFrom instead of Load . But this is not a completely clean solution if the loadable library has dependencies on the libraries of the main application.

  • For the description of the section in the config file, thank you very much, this is exactly what helped. PS I could not load differently, because I just had to allow loading arbitrary libraries (although I took only certain classes from there) - craimez
  • @craimez: That's great, well, that helped. - VladD