"Essential. Net" Reading notes-Chapter 2

Source: Internet
Author: User
Tags config file system include reflection valid versions root directory
Notes
Chapter 2



1. CLR programs exist in Modules (module). A CLR module is a byte stream stored in a file (local or remote server).



2. The CLR module uses an extended version of the Winnt PE (portable executable)/coff (Common Object File format). The CLR module is also a valid WIN32 module that can be loaded through LoadLibrary system calls. The Pe/coff used by CLR modules is minimal, and most of the content is using the. Text section of the Pe/coff file.



3. CLR modules include code, metadata, and resources. Code is stored using CIL (Common intermediate Language) format (Personal understanding: this and MSIL or IL is a thing). The module's metadata describes the types defined in the module, including names, inheritance relationships, method signatures, and dependencies. A module's resources consist of static, read-only data (strings, bitmaps, and so on).



4. (/t:exe,/t:winexe,/t:library,/t:module) module produces "Unprocessed" modules (. netmodule). The module (. dll) generated by the/t:library compilation contains metadata. /t:exe generates a console program,/t:winexe generates a win program.



5. The starting point is one of four forms: static void Main () {}, static void Main (string[] argv) {}, static void Main () {return 0}, static void Main ( String[] argv {return 0}. Whether there is public does not matter, a program cannot have multiple portals, multiple main functions need to use the/main switch at compile time.



6. An assembly (assembly) is a logical collection of one or more modules. An assembly is referenced by a location-independent name. The name must be translated into a physical path on the file system or on the Internet, eventually pointing to one or more modules that contain type definitions, code, and resources.



7. The role of "multi-module" is to distinguish between "common" and "infrequently" code loading (which can be done at runtime "what to Download"), can be used to write the bottom of a language, a language to write the interface.



8. A module often belongs to only one assembly, and if a violation is required, the public module will be generated with two unwanted copies.



9. Modules rely on types from other assemblies (at least in mscorlib.dll), each module has a list of assembly names, and the CLR is responsible for converting the names of these assemblies to the path name of the module at run time.



10. Each assembly has an assembly manifest (assembly manifest), which is part of the metadata equivalent to the attached file directory of the additional type definition and code.



11. A module containing an assembly manifest is first loaded by the CLR and then loaded with the remainder of the module without the manifest based on the contents of the manifest.



12. Refer to another module using the/addmodule switch, referencing another assembly using the/R switch.



13. A module containing an assembly manifest will contain a primary list of external reference assemblies. The list consists of dependencies for each module in the assembly, so that all of the assembly's dependencies can be found by loading a file.



Internal causes only the modules of the same assembly to be available; Public causes all the code to be available; private only the method of that type is available, protected makes the method of the derived class accessible to the member, etc. protected and internal can be used together.



15. Namespace (namespace) + class name.



16. Each assembly uses a four-part (four-part) name as a unique identifier. These four parts are divided into name, culture, developer, component version. These names are placed in the assembly manifest, and when loaded, the CLR finds the correct component using four assembly names.



17. The name of each assembly has a version number: Major.Minor.Build.Revision, if the version number is not explicitly set, then 0.0.0.0. System.Reflection.AssemblyVersion can accept various string formats (1.2.D.S, etc.).



The CultureInfo feature identifies the language and country Code (locale) in which component development is used. Assemblies that contain CultureInfo attributes cannot include code and must be an assembly (resource-only) of "pure resources". The assembly that contains the code is culture-independent (culture-neutral).



19. The assembly name contains a "public key", which identifies the developer of the component. You can choose to use a 8-bit or 128-bit public key token so that you can mark different assemblies with the same file name.



20. Sometimes the assembly must be referenced manually. The CLR defines a standard format that is used to write strings for four parts of an assembly's name. This format is referred to as the display name of the assembly (displays): Name, virsion=x.x.x.x, CULTURE=[XX-XX | Neutral], publickeytoken=[xxxxxxxxxxxxx | Null]. Culture for neutral indicates that the Assembly has no cultural restrictions, PublicKeyToken NULL indicates no public key. Simply omitting the qualified name of a section allows matching of any culture or publickeytoken.



21. In general, you should avoid using partially qualified names of assemblies, otherwise the CLR might run in unexpected ways. You can write the full name in the configuration file and then use a partial name in the program to invoke (Assembly ASSM = Assembly.Load ("XXXX")). Partialname (xxxx above) must exist in the partialname of the configuration file



The CLR will try to load unwanted modules as little as possible and load them when they are actually used. This reduces initialization time and also reduces the resources that are consumed by running programs. CLR loading is triggered by a JIT compiler based on a type that, when JIT compiles the CIL of the method body into machine code, the local variables to be accessed, and the data types such as parameters are loaded together.



23. If you don't want the CLR to load modules repeatedly, there are two ways to do it: one is to define some static fields. The second is to manually explicitly load.



24. If you want to interact explicitly with the assembly, you need to use the System.Reflection.Assembly LoadFrom method, which can be a local file, or "file://..." if it is from a non "file://..." URL, the Web Permission is required, and the module is downloaded first into the cache when it is loaded.



25. Although it is interesting to load assemblies by location, most assemblies are loaded by name by the Assembly parser (Assembly resolver). The method is the System.Reflection.Assembly load method, involving the directory, versioning, and other configuration details.



26. The Assembly parser first uses a valid versioning policy (version policy), which may then load an alternate version of the required assembly (different versions of the assembly are different assemblies, but the assembly mappings must have the same name). Version policy can only be applied to a fully qualified assembly of four part names. If the assembly name is partially qualified (such as a missing public key token, version, or culture) then the version policy cannot be used (directly using the LoadFrom method because the file is specified, there is no version policy issue).



27. The version policy can be determined by the configuration file, and the computer-wide (machine-wide) configuration file is machine.config and exists in%systemroot%\microsoft.net\framework\v1.0.nnnn\ Config directory. For application-scoped (application-wide) configuration files, the normal application is the application directory with the config extension after the file name is the exe file name. Asp. NET is web.config.



28. The configuration file is an XML language file, and there is always a configuration root element. These configuration file settings control the probing path and Publisher version policy mode. In addition, the dependentassembly element is used to make version and location settings for each dependent assembly. (The configuration file has an example on the P36 page of the Chinese version).



29. Version policy is specified at three levels: application (per application) à component (per component) à machine (per machine). The former is output as the latter input.



30. In addition to the specific application and computer-wide configuration files, the given Assembly also has publisher policy (publisher policy). It is stated by the developer to indicate which versions are compatible with each other.



31. The Chinese version of P39 page-shows the entire process of finding the appropriate assembly file for the Assembly parser.



32. To avoid ambiguity, the assembly parser looks for the GAC only if it contains a public key in the requested assembly name. The public key can be provided either explicitly as an assembly reference or as part of the Assembly.Load parameter, or implicitly through a qualityassembly configuration file.



The GAC is controlled by system-level components (FUSION.DLL) to store the DLL cache in the%winnt%\assembly directory.



CODEBASE hint Profile instance: Chinese version P41 page



35. If the assembly parser cannot locate the assembly through either the GAC or the CODEBASE hint, the assembly parser will find the directory related to the application root directory. This lookup is called probing (probing). (Chinese book P43-p45 page)



36. The assembly is versioned into a unit. If you replace a subset of the files in an assembly without updating the version number, it will result in unpredictable results. If the functional conventions of a type change, the assembly of the type must be given a new version number.



CodeBase hints that the private probe path and the GAC can support multiple versions of parallel installations, which allow multiple versions of a given assembly to coexist peacefully in the file system. However, if more than one such assembly is actually loaded into memory by a stand-alone program or a single program, things are unpredictable in some way. Parallel execution is much harder to do than parallel installations.



38. The shared type needs to be deployed to a separate assembly, which itself will not be versioned. (similar to the description of the interface application in applied).



39. The original data used for the Assembly has three special features that allow developers to make the version of the assembly available to be loaded at the same time. These metadata are ignored by the current assembly parser and loader. However, they do have a hint that this hint is expected to be implemented in a future version of the CLR.




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.