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;" }) ;}