Modify the private path of the application search assembly

Source: Internet
Author: User

This is a small example in today's lecture. It demonstrates how to add a search path for. NET applications.ProgramYou can find the relevant Assembly. because. by default, the net program only searches in its own root directory and GAC. Therefore, after the following configuration is added, you can search under the Plugins directory.

 
<? XML version ="1.0"Encoding ="UTF-8"?> <Configuration> <runtime> <assemblybinding xmlns ="Urn: Schemas-Microsoft-com: ASM. V1"> <Probing privatepath ="Plugins"/> </Assemblybinding> </runtime> </configuration>
 
 
 
 
 
You must also want to know howCodeIt does not seem difficult to implement such a function, right?
 
We found that there is a class called appdomainsetup class, and then it has a property called privatebinpath. Isn't that what it is?
 
But please read this blog with patienceArticleHaha
Http://www.cnblogs.com/nullreference/archive/2010/02/09/set_appdomain_privatebinpath_and_configurationfile_location.html
 
 
 
This design is a little weird .. However, not satisfied
 
 

During the debugging process, we also found that the main method is not the best, so we put the code in the static Construction Method of program, this is the earliest starting place except for static fields.

  static  Program () {appdomain. currentdomain. setdata ( "private_binpath" ,  "Castle; core; module; UI; MISC; "); appdomain. currentdomain. setdata ( "binpath_probe_only" ,  "Castle; core; module; UI; MISC; "); var M =  typeof  (appdomainsetup ). getmethod ( "updatecontextproperty" , bindingflags. nonpublic | bindingflags. static); var funsion =  typeof  (appdomain ). getmethod ( "getfusioncontext" , bindingflags. nonpublic | bindingflags. instance); M. invoke ( null ,  New   Object  [] {funsion. invoke (appdomain. currentdomain,  null ),  "private_binpath" ,  "Castle; core; module; UI; MISC;" }) ;}

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.