Read the Classics-"CLR via C #" (Jeffrey Richter) Notes _ Advanced Management Control (configuration)

Source: Internet
Author: User

An example of an application's XML configuration file:

<?XML version= "1.0"?><Configuration>  <Runtime>    <assemblybindingxmlns= "Urn:schemas-microsoft-com:asm.v1">          <probingPrivatePath= "Auxfiles;bin\subdir" />          <dependentassembly>              <assemblyidentityname= "Jefftypes"PublicKeyToken= "32AB4BA45E0A69A1"Culture= "neutral" />            <BindingRedirectoldversion= "1.0.0.0"newversion= "2.0.0.0" />           <CodeBaseversion= "2.0.0.0"href= "Http://www.Wintellect.com/JeffTypes.dll" />          </dependentassembly>           <dependentassembly>              <assemblyidentityname= "TypeLib"PublicKeyToken= "1f2e74e897abbcfe"Culture= "neutral" />               <BindingRedirectOldverison= "3.0.0.0-3.5.0.0"newversion= "4.0.0.0" />                <publisherpolicyApply= "No" />           </dependentassembly>     </asssemblybinding>   </Runtime></Configuration>

This XML file provides a wealth of information for the CLR. The details are as follows.

    • probing element   Check the auxfiles and Bin\subdir subdirectories of the application base directory when looking for a weakly named assembly. For strong-named assemblies, the CLR checks the GAC or the URL specified by the CODEBASE element. The CLR checks a strong-named assembly in the application's private path only if the CODEBASE element is not specified.
    • First dependentassembly,assemblyidentity and bindingredirect elements   Lookup by controlling the public key token 32AB4BA45E0A69A1, the organization that published the language culture for the neutral jefftypes Assembly of 1.0.0.0, instead locates version 2.0.0.0 of the same assembly.
    • codebase  element finds published by an organization that controls the public key token 32ab4ba45e0a69a1  Language culture for the neutral Jefftypes 2.0.0.0 version of the assembly, try to find it at the following URL:www.wintellect.com/jefftypes.dll  need to indicate that the CODEBASE element can also be used for weakly named assemblies. In this case, the version number of the assembly is ignored, and the version number should not be written in the xmlcodebase element at all. In addition, the URL defined by codebase must refer to a subdirectory under the application base directory.
    • Second  dependentassembly,assemblyidentity and bindingredirect elements lookup is controlled by the public key flag The organization of the 1f2e74e897abbcfe  published, the language culture for the neutral typelib assembly 3.0.0.0 to 3.5.0.0, including 3.0.0.0 and 3.5.0.0, instead locates the 4.0.0.0 version of the same assembly.
    • publisherpolicy  element   If the organization that generated the TypeLib assembly deploys a publisher policy file , the CLR should ignore the file.

When you compile a method, the CLR determines which types and members it references. Based on this information, the runtime examines the AssemblyRef table of the assembly that issued the reference and determines which assemblies are referenced by the Assembly at the time of the build. The CLR then checks the assembly/version in the application configuration file and makes any version number redirection operations that are set. Next, the CLR looks for a new, redirected assembly/version.

If the Publisherpolicy element's apply attribute is set to Yes, or if the element is omitted, the CLR examines the new assembly/version in the GAC and makes any version number redirection operations that the Assembly publisher deems necessary. The CLR then looks for new, redirected assemblies/versions. (about the publisher policy has a note record of the grabs) Finally, the CLR examines the new assembly/version in the machine's Machine.config file and makes any version number redirection operations that are set.

To this end, the CLR already knows the version of the assembly it should load and tries to load the assembly from the GAC. If the assembly is not in the GAC and there is no codebase element, the CLR probes the assembly. If the configuration file that performs the last redirection operation contains both a CODEBASE element, the CLR attempts to load the assembly from the URL specified by the CODEBASE element.

With these configuration files, administrators can actually control the assembly that the CLR loads. If a bug occurs in an application, the administrator can contact the publisher of the problematic assembly. The publisher can send a new assembly to the administrator for the administrator to install. The CLR does not load this new assembly by default because the assembly that has been generated does not have a new version of the reference. However, an administrator can modify an application's XML configuration file to instruct the CLR to load a new assembly.

If the administrator wants all applications on the machine to use the new assembly, you can modify the machine's Machine.config file (instead of modifying the application's configuration file). Whenever an application references an assembly, the CLR automatically loads the new assembly.

If you find that the new assembly does not fix the original bug, the administrator can remove the BindingRedirect setting from the configuration file and the application will revert to the same.

Highlights: The system allows the use of an assembly version that is not exactly matched to the metadata that is recorded.

Read the Classics-"CLR via C #" (Jeffrey Richter) Notes _ Advanced Management Control (configuration)

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.