[C #] C # learning notes-assembly

Source: Internet
Author: User

C # Study Notes-ProgramSet

Luo chaohui (http://www.cnblogs.com/kesalin)

Book notes on C # And. Net Advanced Programming

 

1. An assembly is a versionized, self-described binary file that uses the Common Language Runtime Library (CLR) as the host, although in reality.. Net assembly and Win32 binary files have the same extension (*. EXE or *. DLL), but the internal structure of the two is almost completely different. C # the Assembly has the following features: Use the namespace to determine the type boundary; Be versionable; be self-described (you do not need to access the Registry to locate); It is configurable.

2. The Assembly format includes the following parts: Win32 file header, CLR file header, and CERCode; Type metadata; assembly list; optional embedded resources. We can use dumpbin.exe to view the Win32 file header and CLR file header, and use ildasm.exe or reflector.exe to view the CE code, metadata, or list of the Assembly.

Win32 file header: it enables the Assembly to be loaded or operated by windows;

CLR file header: it defines multiple tags so that the runtime can understand the layout of hosted files. These tags identify the location of metadata and resources in the file, the running version of the Assembly build, and (optional) Public key values.

Template code: the template code is the core of a set of programs and is an intermediate language independent of the platform and CPU. At runtime, the inside of the Assembly can only be compiled into specific platform and CPU commands (Real-Time JIT compiler. This mechanism ensures that the. NET assembly is cross-platform and cross-language.

Metadata: it fully describes the Assembly inclusion type and the format that references the external type. The runtime makes remote method calls more convenient by using the location of the parsing Type (and type members) in the binary layout of the memory. In addition, the Assembly must be associated with a manifest. This list details each module in the Assembly, the build assembly version, and all external Assembly referenced by the Assembly.

Optional embedded resources: Embedded resources can include application icons, images, sounds, or string tables, as well as ancillary components (including only localized resources ).

3. All necessary parts of a single file assembly (header information, pencil code, type metadata, list and required resources) are included in a *. EXE or *. dll package. A multi-file assembly is a collection of. Net *. dll. These DLL are deployed and versioned as a single logical unit. Generally, one of them serves as the main module and will contain the Assembly-Level list (as well as necessary Council code, metadata, header information and optional resources ). The list of the main module records every *. dll file it depends on. According to naming conventions, the file extension of the auxiliary module of Multi-file assembly is *. netmodule, but this is not mandatory. The auxiliary module also contains the pencil code and type metadata, and a module-Level list that records the Assembly referenced externally by the module. Multi-file assembly has the following advantages: it improves the efficiency of program loading-it can be loaded on demand; it allows modules to be loaded by different. net Programming Language Write. Modules that make up a multi-file assembly are not connected to each other into a large file. They are logically connected by the information recorded in the master module list. 4. Private assembly must be placed in the directory where the client application is located or in its subdirectory. We assume that the private assembly does not need to be checked in detail, because the client application is the only entity that knows its existence .. Net runtime environment uses a technology called probing to parse the location of a private assembly. This technique maps external Assembly requests to the requested binary file. Strictly speaking, a load request can display or implicitly. Implicit loading requests occur when the. Assembly extern mark of the CLR query list is used to parse the Assembly location. An explicit loading request occurs when the system is called programmatically. reflection. when using the load () or loadfrom () Methods of the Assembly class, these two methods are mainly used for later binding or dynamic calling of type members. Whether explicit or implicit, after the CLR obtains the Assembly name, it starts to detect * under the client application directory (and its subdirectories *. DLL file. If not, try to find the executable assembly with the same name *. EXE. If not found, the filenotfound exception is thrown. Of course, you can also create a configuration file in *. config format to modify the detection rules. 5. A shared assembly is a collection of types and (optional) resources. The difference between a shared assembly and a private assembly is that a copy of the shared assembly can be used by multiple applications on one machine. The shared assembly is installed in GAC, and GAC is named assembly in the Windows directory (for example, c: \ windows \ assebly ). An assembly is assigned a strong name before it is deployed to GAC. The strong name identifies the publisher of the Assembly, and its role is similar to the guid in COM. Strong names are based on cryptographic public keys and private keys. This mechanism is more unique and tamper-resistant than guid. A strong type is composed of a set of related data: the name, region number, and public value (generated by sn.exe) of the program set. It is used for localized optional regional identifiers and embedded digital signatures.
Related Article

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.