Assembly Loading involves a lot of knowledge, including configuration files, global cache assembly, and searching for private directories. To load an assembly using the loadawithpartialname method, you must provide the text name of the Assembly. You can also set the Public Key tag, version, or culture, but do not need to include fully referenced information, such as name, version, culture, and public key tag.
Use (system. reflection. Assembly. Load) and specify only partial references. The Runtime Library checks the assembly in the Global Assembly Cache and application root directory. Use the loadwithpartialname method and specify only partial references. The Runtime Library checks the assembly in the application directory and in the Global Assembly Cache. In addition, some references are provided to provide complete references in the application assembly configuration file.
Use load to find partially referenced assembly:
1. Check in the application configuration file
<Qualifyassembly> refers to the related limitation information in the element. If it is found, some referenced restriction conditions are converted to new reference conditions. Suppose:
<qualifyAssembly partialName="mydll" fullName="mydll,version=1.0.0.1,publicKeyToken=xxx,culture=zh-CN">
Assembly A = assembly. load ("mydll"); converts the condition to a stronger condition "mydll, version = 1.0.0.1, publickeytoken = xxx, culture = ZH-CN ".
2. Match in Global Assembly Cache according to specified conditions
If one or more matching items exist, take the first matching assembly and go to step 1. Otherwise, go to step 2.
3. Matching Based on stronger conditions under the application directory
If one or more matches, take the first one and enter Step 1. Otherwise, local reference fails.
4. if the version policy is specified, apply the Version Policy to the matching assembly.
<Dependentassembly>
<Assemblyidentity
Name = "mydll" publickeytoken = "XXX" Culture = "ZH-CN"> </assemblyidentity>
<Bindingredirect
Oldversion = "1.3.0.0" newversion = "1.2.0.0"> </bindingredirect>
</Dependentassembly>
According to the version policy, the latest version "mydll, publickeytoken = xxx, culture = ZH-CN, version = 1.2.0.0" is loaded ". If loadpartialname is used, it is first matched from the application root directory. If no match is found, it is matched from the Global Assembly Cache... the version policy is also applied. During the matching process, the regional cultural issues should also be taken into account, such:
<Configuration>
<Runtime>
<Assemblybinding
Xmlns = "urn: Schemas-Microsoft-com: ASM. V1">
<Qualifyassembly
Partialname = "mydll" fullname = "mydll, version = 1.2.0.0, culture = ZH-CN, publickeytoken = xxx"/>
<Dependentassembly>
<Assemblyidentity
Name = "mydll", publickeytoken = "XXX" Culture = "ZH-CN"/>
</Dependentassembly>
<Bindingredirect
Oldversion = "1.2.0.0" newversion = "1.3.0.0">
</Assemblybinding>
</Runtime>
</Configuration>
The Global Assembly Cache contains:
Mydll, version = "1.2.0.0", publickeytoken = xxx, culture = ZH-CN
And
Mydll, version = "1.3.0.0", publickeytoken = xxx, culture = en-US
Private directories include:
Mydll, version = "1.3.0.0", publickeytoken = xxx, culture = ZH-CN
Mydll, version = "1.3.0.0", publickeytoken = xxx, culture = en-US
In the private Directory: mydll, version = "1.3.0.0", publickeytoken = xxx, culture = ZH-CN
The first step is to convert it to a stronger condition: mydll, version = "1.2.0.0", publickeytoken = xxx, culture = ZH-CN, search for it in the Global Assembly Cache, and search for matching based on the culture, if version 1.3.0.0 is not found after the application version policy matches the region, it is matched in the private directory...