. NET Framework Program design reading Notes II (Microsoft. NET Framework Development platform architecture) __.net

Source: Internet
Author: User

Chapter One: Microsoft. NET Framework Development platform Architecture <?xml:namespace prefix = o ns = "Urn:schemas-microsoft-com:office:office"/>

Objective of this chapter: to have a general understanding of the. NET Framework architecture and to have a basic understanding of some of the new technologies and terminology that appear in the. NET Framework.

1.1 Compiling the source code into a managed module

about the choice of programming language

The core of the. NET Framework is the common language runtime, as the name suggests it is a runtime that can be used by various programming languages. Many of the features of the CLR are available to all programming languages that are oriented to it, and if the CLR reports errors with exceptions, all languages that face it will get error reporting through exceptions. If the CLR allows us to create threads, then all languages that are oriented to it can also create threads.

In fact, the CLR does not know at runtime what programming language the developer uses to complete the source code. This means that we should choose the programming language that is the easiest to express our intentions. We can write code in any language we like (CLR-oriented).

Different programming languages allow us to develop using different grammars, and different grammars have an impact on how easy it is for us to solve a variety of problems, such as: for math or financial applications, color APL syntax is faster.

Microsoft has created the following CLR-oriented compilers:

Managed Extensions C + +

C#

Visual Basic

Jscript

J #

Il assembler

We can use any programming language that supports the CLR to create source code files. Then use the corresponding compiler to do the grammar check and source code analysis. Finally, the managed oak block is generated.

Managed Modules

 

A managed module is a standard Windows Portable executable (portable executable, referred to as PE) that requires the CLR to execute File.

 

Components of managed modules :

L PE Table Head

Standard Windows PE file header, similar to universal pair like file format headers. The table header indicates the type of file: GUI (graphical user interface), CUI (console user interface), or DLL. The DLL here is not the traditional Windows Dynamic link library file We understand, although it is called a DLL, but the DLL in the net platform refers to a form of the assembly file, and the header also contains the file creation time. For modules that contain CPU code, the header also contains some information about the local CPU code

L CLR Header

Contains information that identifies a managed module (which can be parsed by the CLR or some utilities).

1, CLR version number

2. Metadata token for the managed module entry point method (Main method)

3, the managed module metadata token

4. Resources

5. Strong naming

6, some other meaning is not too large information location and size

L Meta Data

Each managed module contains a number of metadata tables. The metadata table is divided into two main categories, one for describing types and members defined in the source code, and one for describing reference types and members in source code.

L Intermediate Language (IL) and code

The compiler compiles the source code as the resulting instruction. The CLR compiles the IL code to a cost CPU instruction at run time

Meta data (metadata is a collection of data tables in which some describe what is defined in the managed module (such as the defined types and their members, and others that describe what is referenced in the managed module, such as the referenced type and their members). The metadata is always associated with the file that contains the IL code.

the use of metadata:

1, save the source code compile the right file and library file requirements,

2, Visual Studio. NET can use meta data to help us write code. That's what IntelliSense does.

3. Can be serialized and deserialized

4. The garbage collector can trace the lifetime of the image.

1.2 Combining managed modules into assemblies

The CLR does not actually deal with managed modules, and the object it deals directly with is the Assembly (Assembly). An assembly is an abstract concept that is often difficult to understand at first. First, the assembly is one or more managed modules, and a logical combination of some resource files. Second, the assembly is the smallest unit of component reuse, and the implementation of security policies and versions. Depending on our choices for compilers and related tools, the assembly can be a file or multiple files.

By default, the compiler converts the resulting managed module to an assembly. In other words, the C # compiler produces a managed module that I include in the manifest. The manifest indicates that the assembly contains only one file. For projects that contain only one managed module and no resources (or data) files, the assembly is the managed module, and no additional steps are required during the creation process.

The module in the Assembly also contains some information about the assembly that it references, such as version number information. This information enables an assembly to implement Self-describing (self-describing). In other words, the CLR knows all the content needed to execute an assembly, and it does not need to get additional information in the registry or in the Active Directory. Therefore, the deployment of an assembly is much easier than the deployment of an unmanaged component.

1.3 Load Common Language runtime

An assembly is either an executable application or a DLL that contains a set of types (components) for use by an executable application. The CLR is responsible for managing the execution of code contained in the Assembly. This means that the host must have the. NET Framework installed. Microsoft has created a distribution package that can install the. NET Framework free of charge to clients. The. NET Framework is ultimately packaged with future windows so that we do not need to put it together with our assemblies for publication.

We can determine if the. NET Framework is installed in a machine by looking up the MSCorEE.dll file in the%windir%/system32 directory. If you want to determine which versions are installed in a machine. NET Framework, you can view the subkeys of the following registry key:

Hkey_local_machine/software/microsoft/. Netframework/policy

When an EXE assembly is generated, the compiler/linker generates special information and embeds them into the. Text portion of the PE file header of the resulting assembly and its constituent files. When an EXE file is invoked, these special information causes the CLR to be loaded and initialized. The CLR then navigates to the entry point method of the winning program, starting the application from the side.

Similarly, if an unmanaged application loads a managed assembly by calling LoadLibrary, the entry point function of the managed assembly DLL also knows to load the CLR to handle the code contained therein.

managed EXE Load and initialize CLR the process

1. Mscoree checks the CLR header to obtain the metadata token for the main method.

2. Mscoree examines the metadata of the main method to obtain its IL position in the managed EXE.

3. Mscoree the Il of the main method to compile the cost CPU instruction.

4. Mscoree jumps to the local CPU instruction compiled by the main method (using the main thread)

5. The application begins to run.

The case of a managed DLL is similar to this.

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.