C# How to redirect assembly loading using application config file

别说谁变了你拦得住时间么 提交于 2019-12-10 19:05:26

问题


I have an assembly with few versions registered in the GAC. Now, I want one of my clients which uses this assembly (version 1.3) to point to the newest version (1.4) without opening the source and recompiling the client.
I saw an article demonstrating a technique for doing so using the application config file (winform application)

here is the config file content :

<?xml version="1.0" encoding="utf-8" ?>
<configuration xmlns:asm="urn:schemas-microsoft-com:asm.v1">
<runtime>
<asm:assemblyBinding>
  <!-- one dependentAssembly per unique assembly name -->
  <asm:dependentAssembly>
    <asm:assemblyIdentity
       name="MyFacade"
       publicKeyToken="c9c18e16df1654e0" />
    <!-- one bindingRedirect per redirection -->
    <asm:bindingRedirect oldVersion="1.3.0.0"
                  newVersion="1.4.0.0" />
  </asm:dependentAssembly>
</asm:assemblyBinding>
</runtime>
</configuration>

As you can see, there is a binding redirect from version 1.3.0.0 to 1.4.0.0 for assembly named MyFacade.

Now, there's only a Minor issue with this approach. It doesn't work :)

I'm sure it's something with my code.

Any suggestions?

Thanks,
Adi Barda


回答1:


first, this is the best source I've found about this subject. There are some differences, for example, they are not using the asm: namespace, and also, you might want to disable the publisher policy by adding <publisherPolicy apply="no" /> as described in the article.

In a previous project we did, we needed even more control, so we needed to catch the AppDomain.AssemblyResolve Event and route to any assembly we wanted. Here you can find more informations about the concept. You'd have to manipulate your app once, though.



来源:https://stackoverflow.com/questions/2942767/c-sharp-how-to-redirect-assembly-loading-using-application-config-file

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!