Access to resources in the assembly encumbered through Assembly.Load



  • There is a library in which a method with such a 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.resxwhich is compiled Reports.resources.dll I don't know if I have to do that.

    If the library is directly connected, when the method is called, everything everything works well, the necessary resource file (they few) can be accessed.

    But if you connect the library software through Assembly.Load()to create a class object and to produce the same method, the resource file is not available.

    Question, what do we do? How do you make the second case properly count the resource?



  • If you load your collection through Assembly.Loaddependence is sought at the same location as the main application, i.e. in the annex catalogue and its subcategories of species en-USru-RU (for language resources). The investigation in the commentaries showed that your files were in the subcategory. Dataand therefore no localized resources.

    The simplest solution is to transfer the library to the core programme catalogue and its localization to the subcategories. en-USru-RU etc. of the programme catalogue.

    The other way is to change the configuration of the programme by allowing it to depend on other catalogues. https://msdn.microsoft.com/en-us/library/823z9h8w.aspx that we need to put the section in. app.config:

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

    Strict road, indicating publicKeyTokendescribed https://support.microsoft.com/en-us/kb/837908 (this path will prevent the Anything.and only allow for the loading of the required 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're gonna have to sign a collection (and also dependent local localized kits!) with help. sn -k

    Another way described there is to sign for the event. AssemblyResolveand load the assembly through LoadFrom In it.


    Well, according to https://blogs.msdn.microsoft.com/suzcook/2003/05/29/choosing-a-binding-context/ Can help you. LoadFrom instead Load♪ But it's not a pure solution if the encumbered library has dependence on the library of the main application.




Suggested Topics

  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2