.NET Framework Design Reading Note 2 (Microsoft .NET Framework Development Platform Architecture)

zhaozj2021-02-16  52

Chapter 1: Microsoft .NET Framework Development Platform Architecture

The goal of this chapter: There is an overall understanding of the .NET framework architecture, and has a basic understanding of some new technologies and terms that appear in the .NET framework.

1.1 Compile the source code as a managed module

About programming language selection

The core of the .NET framework is a generic language running, as the name suggests it is a run when it is used by various programming languages. Many of the CLR can be used for all programming languages, if the CLR is reported to report an error, then all languages ​​facing it will receive an error report through an exception. If the CLR allows us to create a thread, all languages ​​facing it can also create threads.

In fact, the CLR does not know where the programming language is used to perform the source code at runtime. This means that we should choose the programming è most easily expressing our map. We can write code ã with any language (facing CLR),

Different programming languages ​​allow us to develop different syntax, different syntax has an impact on our solutions to we solve various problems, for example: for mathematics or financial applications, the APL syntax is faster.

Microsoft has created several of the following CLR-oriented compilers:

Hosting expansion C

C #

Visual Basic

JScript

J #

IL assembler

We can create a source code file with any programming language that supports CLR. Then use the corresponding compiler to do a syntax check and source code analysis. Finally, a hosted rubber is generated.

Hosted module

The hosting module is a standard Windows that can be implemented (PE) files that require CLR to perform (PE) files.

Component part of the hosted module:

l PE header

Standard Windows PE file header, similar to general-purpose log file format header, The header points out 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 DLL, but The DLL refers to the DLL of the NET platform, which also contains file creation time. For modules containing the CPU code, the header also contains some information about the local CPU code.

l CLR header

Contains some information identified by the managed module (can be parsed by the CLR or some utility).

1, CLR version number

2. Metadata tag of managed module entry point method (Main method)

3, metadata tag of the hosting module

4, resources

5, strong naming

6, other significance is not too large, the location and size of information

L metadata

Each managed module contains some metadata tables. The metadata table is mainly divided into two, one for describing the type and member defined in the source code, one for describing the reference types and members in the source code.

l Intermediate language (IL) and code

The compiler is a directive generated in compilation source code. CLR will compile IL code cost CPU instructions at runtime

Metadata is a collection of data tables, in which some of them are used to describe content defined in the managed module (such as the defined type, and members, others are used to describe the managed module) Content (such as the type being referenced and its members). The metadata is always associated with a file containing the IL code.

The use of metadata:

1. The demand for the header file and library files when the source code is compiled.

2, Visual Studio .NET can use metadata to assist us write code. Intelligence is doing this.

3, can serialize and deserialize

4. The garbage collector can track the survival of the image.

1.2 combination of managed modules as assemblies

The CLR is actually not dealing with the managed module, and the object that is directly dealing with the assembly (assembly). The assembly is an abstract concept, and it is often difficult to understand. First, the assembly is one or more managed modules, as well as logical combinations of some resource files. Second, the assembly is the component multiplexing, and the minimum unit of implementing security policies and versions. Depending on our choice made to compilers and related tools, the assembly can be a file or multiple files. By default, the compiler converts the generated managed module into an assembly. That is, the C # compiler generates a hosted mode I contain a list. The list indicates that only one file is included in the assembly. For items that contain only one hosting module, and there is no resource (or data) file, the assembly is a managed module and does not need to perform any other steps during the creation process.

The module in the assembly also contains some information (such as version number information). This information makes a program set to achieve self-description. In other words, the CLR knows all the contents required to perform a program set, which does not need to get additional information in the registry or active directory. Therefore, the deployment of the assembly is much easier than the deployment of the non-hosting components.

1.3 Loading a general language running

An assembly or an executable application, or a DLL containing a set of types (components) for executable applications. The CLR is responsible for managing the execution of the code contained in the assembly. This means that the host machine must be installed .NET framework. Microsoft has created a distributing package that can be installed free to the client to the client free of charge. The .NET framework will eventually package with the future Windows so we don't need to put it and our assembly together.

We can determine if a .NET framework is installed in a machine by looking for a MSCoree.dll file in the% WINDIR% / System32 directory. If you want to determine which version of the .NET framework is installed in a machine, you can view the sub-key of the following registry keys:

HKEY_LOCAL_MACHINE / SOFTWARE / Microsoft / .Netframework / Policy

When generating an EXE program set, the compiler / linker generates some special information and embeds them into the PE file header of the result assembly and its respective components .Text section. When the EXE file is called, these special information will cause the CLR to be loaded and initialized. The CLR will then be positioned to the entry point method of the winning program, and start the application from the face.

Similarly, if a unmanaged application is loaded by calling LoadLibrary to load a managed assembly, the entry point function of the managed assembly DLL will also know that the CLR is to process the code contained therein.

The process of hosting EXE loads and initializing CLR

1. MSCOREE Check the CLR header to obtain metadata tags for the main method.

2. Mscoree Check the metadata of the MAIN method to obtain the location of its IL in the hosted EXE.

3. Mscoree compiles the IL of the Main method CPU instruction.

4. MSCOREE jumps to the local CPU instruction after MAIN method (using the main thread)

5. The application starts running.

The case of hosted DLL is similar to this.

转载请注明原文地址:https://www.9cbs.com/read-27017.html

New Post(0)