Is it possible to set assembly probing path w/o app.config?

别等时光非礼了梦想. 提交于 2019-12-05 15:08:07

问题


I need to place DLLs for my application inside subfolder. It is possible to set this subfolder via app.config:

  <runtime>
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
      <probing privatePath="Libs"/>
    </assemblyBinding>
  </runtime>

But for some reasons I don't want to use .config file in this case. Is it possible to set probing path directly from application code? I am sure that DLLs always be within this folder.

Any ideas?


回答1:


The probing path is defined by the AppDomainSetup for the primary app domain. In the default CLR host, that AD gets automatically created before your code starts running. The only way to configure its setup is to use a .config file, it must have the same name as the exe. After which it is frozen, any changes you make in your code won't have an effect.

Workarounds are to create your own AD so you can change its setup or implementing the AppDomain.AssemblyResolve event. Neither of which compares favorably to the simple solutions: a .config file or just keeping the assembly in the right directory. Ymmv.




回答2:


You could just subscribe to AppDomain.CurrentDomain.AssemblyResolve and check your specific location in your handler...



来源:https://stackoverflow.com/questions/5220349/is-it-possible-to-set-assembly-probing-path-w-o-app-config

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