Understanding of the. NET Platform

Source: Internet
Author: User
Tags hosting

Re-learn. NET Framework, where the. NET Framework will be progressively learned. Deepen your understanding of. Net.

With limited knowledge, get to know what the. NET contains first. Some have seen it from somewhere else. The feeling is good to write down.

Intro: What is. NET Framework

. The NET Framework is a multi-language component development and execution environment that provides a unified programming environment across languages. NET Framework is designed to make it easier for developers to build Web applications and Web services so that Web services can be used to communicate between applications on the Internet. From a hierarchical perspective. NET Framework consists of three main components:

    • Common language Runtime (Clr:common Language runtime);
    • Service framework and two types of application templates on top-Traditional Windows Application Templates (WinForms);
    • ASP. NET-based Web application Templates (Web Forms and Web Services).

One, what is the CTS, CLS, CLR

(1) The CTS (Common type System) is a common type systems. It is mainly used to solve different kinds of data types in different languages, he is a type standard, in this standard not only implements the COM variable compatibility type, but also defines the user-defined way to do type extension, so. NET platform is the target language for interacting with data types in other languages by establishing a mapping between its own data type and the CTS.

(2) The CLS (Common Language specification) is a common language specification that is primarily used to achieve interoperability between multiple languages and is a subset of the public type system.

(3) The CLR (Common Language Runtime) Common language runtime is the programming foundation that all applications use, like a virtual machine that supports. NET applications to run and develop.

See Help understanding.

Two, what is the CTS, CLS, CLR

(1) CTS

CTS, which defines how to declare, use, and manage types in the. NET Framework runtime, as well as an important part of the. NET Framework runtime's support for cross-language fundamentals.

Features: Build a framework that supports cross-language integration, type-safe, and high-performance code execution. Provides an object-oriented model that supports the complete implementation of multiple programming languages. Define the rules that each language must follow to help ensure that objects written in different languages can interact.

Defines the model of the rules that the common language runtime follows when declaring, using, and managing types. A common type system establishes a framework that makes cross-language integration, type safety, and high-performance code execution possible. It is the raw material that you can use to generate the class library.

The common type system supports two categories of types, value types and reference types, respectively.

(2) CLS

The CLS is the common Language specification, which is a set of basic language features required by many applications. CLS rules define a subset of a common type system, that is, all rules that apply to a common type system apply to the CLS, unless stricter rules are defined in the CLS. The CLS enhances and ensures the interoperability of languages by defining a set of capabilities that developers can trust to be available in multiple languages. CLS also establishes CLS compliance requirements that help users determine whether managed code is CLS-compliant and how well a given tool supports the development of managed code, which is using CLS functionality.

(3) CLR

The CLR, the common language runtime, is the foundation of the. NET framework and can be seen as a proxy for managing code at execution time, providing core services such as memory management, thread management, and remoting. It also enforces strict type safety and other forms of code accuracy that can improve security and reliability.

three,. NET 3c:cts, CLS, and CLR

. NET combines the advantages of both Java and COM solutions to solve interoperability issues. Similar to the standard binary format for COM definitions. NET defines a type standard called the Common type system common type systems (CTS). This type of system not only implements the COM variable compatibility type, but also defines the type extension by user-defined type. Any to. NET platform as the target language must establish a mapping between its data type and the type of the CTS. All. NET language to share this type of system, to achieve seamless interoperability between them. The scheme also provides the inheritance between languages. For example, a user can derive a class written by C # in vb.net.

Obviously, the difference between programming languages is not just the type. For example, some languages support multiple inheritance, some languages support unsigned data types, and some languages support operator overloading. Users should be aware of this, therefore. NET limits the interoperability issues raised by these differences by defining common language Specifications (Cls:common Language specification). The CLS has developed a minimal feature that must be supported by a language that targets the. NET platform, as well as the complete characteristics required for interoperability between the language and other. NET languages. Recognizing that this is important, the characteristic issues discussed here are not just simple grammatical differences between languages. For example, the CLS does not care about what keywords a language implements for inheritance, but only about how the language supports inheritance.

The CLS is a subset of the CTS. This means that a language feature may conform to the CTS standard, but is beyond the scope of the CLS. For example, C # supports unsigned numeric types, which can pass the CTS test, but the CLS only recognizes symbolic numeric types. Therefore, if a user uses a C # unsigned type in a component, it may not be designed with languages that do not use unsigned types, such as vb.net. NET components for interoperability. The use of this is "probably not", not "impossible", because the problem actually depends on the visibility of the non-cls-compliant item. In fact, CLS rules apply only to or partially apply to types in components that are associated with other components. In fact, a user can safely implement a project with a private component that uses what the user chooses to use. NET language, without complying with the CLS specification. On the other hand, if the user needs. NET language, the public items in the user's components must be fully CLS-compliant.

The last C is the common language runtime Common Language Runtime (CLR). To put it simply, the CLR is the implementation of the CTS, which means that the CLR is the application's execution engine and a fully functional class library, which is implemented in strict accordance with the CTS specification. As a program execution engine, the CLR is responsible for securely loading and running user program code, including garbage collection and security checks on unused objects. Code that runs under CLR monitoring, called Managed code (managed). As a class library, the CLR provides hundreds of useful types available, which can be extended by inheritance. For file I/O, create dialog boxes, startup threads, and so on-basically, you can do it with the Windows API.
Let's see "3C" correctly. When developers build their own distributed applications, because users face the CLR directly when they are programming, they should focus on learning about the CLR rather than the CTS and the CLS. And for the hope of. NET platform is the target language and tool developer, it requires a deep understanding of the CTS and the CLS. Interoperability components are key to distributed applications and are therefore understood. How NET can achieve this goal by defining a public type is also very important.

Cts,cls,cts. Let's take a look at the most basic environments that are needed to develop and run. Net.

four, development and operation. NET needs of the most basic environment

Let's analyze the following:

(1). NET program Development

The problem is simple, mostly. NET programmers are developing. NET programs on the Visual Studio platform that Microsoft products provide. However, it is important to note that the Visual Studio IDE environment is not the only, necessary tool that can theoretically be written using any text editor. NET code, but because the text editor does not provide the code to compile debugging and syntax hints and other functions, so basically no programmer just use a text editor to write. NET code.

(2). NET to run

Run. NET program is undoubtedly the. NET Framework, you can download the. NET Framework for free on the official website of Microsfot. Run. NET program must have the. NET Framework, which is what you want to run. NET program is the same as the operating system.

Note: currently. NET is not good for cross-platform support, just support the Windows platform, on Linux, Unix systems can not directly install the. NET Framework, can only install third-party mono as an alternative to the. NET Framework, but mono with. Net A series of issues such as the compatibility of the framework and the speed of updates have led to relatively few projects currently being developed using mono.

Summarize:

Development and operation. NET program is required to install. NET Framework components, and of course the Visual Studio IDE must be installed (although a theoretical text editor can also write. NET code, the programmer will actually install Microsoft's Visual Studio products).

We know about the environment, so let's take a look at it. What is the operating mechanism of net

Five,. NET's operating mechanism

(1). NET program is compiled into what form of code

The. NET program forms the CLR header, metadata, and intermediate code after the first compilation.

When running or deploying in real time, a second mutation is made, and the result of the compilation is machine code that can be executed in the CLR;

The-CLR header contains the information that. NET obtains when it runs the program, including the assembly version number, the file name, and the module version number.

-metadata contains all types of definitions, all references, and assembly manifests.

(2) How the JIT works

Before the JIT engine compiles the intermediate code, it looks for the native machine code cache and confirms that it is available:

-if available, load directly;

-If not available, the JIT engine looks for the method stub in the type, finds the intermediate code, and compiles it.

(3) Briefly describe the loading mechanism of the Assembly

The CLR actively loads the assembly through System.Reflection.Assembly.LoadFrom and System.Reflection.Assembly.Load:

-The former loads the assembly by location;

-the latter identifies the assembly by uniquely identifying the four elements of the strong-named assembly;

They are loaded in the same way, and their intrinsic strategy is to find the assembly in turn through version policy, codebase location, application domain location, and program location.

(4) How to configure the version policy for an assembly

The CLR supports setting a version policy at 3 levels, followed by: Application policy, publisher policy, and computer policy.

All of the policy settings are implemented by modifying the configuration file. 3 level policies are executed sequentially by the CLR, and the result of the previous policy is entered as the next policy.

The publisher policy is only for those assemblies that are placed in the GAC (cache) and can be ignored in the application policy.

Now that the assembly is mentioned above, let's look at what the assembly is.

Six, what are assemblies and application domains

Assemblies and application domains are. The NET Framework compares the basic concepts of each. NET programmers are constantly interacting with each other in their daily work. Assemblies and application domains are. NET program packaging and deployment, readers need to understand their basic concepts clearly.

The points of knowledge involved

    • Basic Concepts of assemblies
    • Basic concepts of application domains

Analyze problems

The first is to explain the concept of an assembly. An assembly (Assembly) is a collection of one or more modules and resource files. When an assembly is packaged, it not only contains all the original file contents, but also adds an assembly manifest that contains information such as the assembly's version number, language, publisher, import type, and so on. Interestingly, the assembly manifest can be added to a file in the assembly, and the compiler can create a separate file for the assembly manifest.

An assembly is a logical concept, not one or several physical files or code snippets.

The introduction of the concept of assembly brings great flexibility to the design and deployment of the system.

(1) The Assembly supports multi-programming language development, where an assembly can contain modules that are defined and implemented by different programming languages. When an assembly is compiled, all of these types have been compiled into intermediate code without the original programming language features.

(2) Assemblies allow separation of logical and physical distributions. This way, while belonging to a logical assembly, the various types and resources can still be distributed across different physical files. This greatly improves the flexibility of the system deployment. For example, a programmer can divide an assembly into four files, including a basic type definition, a basic Help document, an optional type definition, and an optional help document. This allows the user to select the required functionality when the system is deployed, and to compose the assembly by downloading the necessary files from the server as the user chooses.

The file that contains the assembly manifest is required for the assembly to be used.

Next look at the concept of the application domain, again, this is a. NET proposed by the new concept. In the operating system, a common application typically occupies an operating system's process. The process of the operating system provides an independent memory space for the application, prescribes the scope of execution of the Code, and provides an error isolation mechanism. In the. NET Framework, application domains (AppDomain) provide features that are very similar to operating system processes. An application running in the CLR that will have at least one application domain. As with the operating system process, the application provides the scope of execution of the code and provides isolation for the program. Communication between multiple application domains is difficult, and each type instance resides within an application domain, and references within all domains must reference the object of their application domain.

Unlike operating system processes, the cost of creating and destroying application domains can be relatively small. Of course, the CLR is still running on the operating system, so an application domain must be running within the process of an operating system, and under the arrangement of the CLR, the process for each operating system can also contain multiple application domains. Figure 2.2 shows this organizational structure.

Answer

An assembly (Assembly) is a logical collection of type definitions, data files, and resource files. Each assembly contains an assembly manifest, which is typically attached to a file header, or you can set up a separate file to contain the manifest.

An application domain is a logical unit in the CLR that provides code-running scopes, error isolation, and security settings that are functionally similar to the operating system's processes. One or more application domains run in the process of an operating system. The cost of creating and destroying an application domain is smaller than the operating system process. However, as with operating system processes, data sharing between application domains is quite difficult.

Now let's see, what are the components of the assembly version?

Seven, what is the composition of the assembly version?

Each assembly has a version number as part of its identity. Therefore, if two assemblies have different version numbers, the runtime will treat them as completely different assemblies. This version number is actually represented as a four-part number with the following format:

< major version >.< minor version >.< build number >.< revision number >

For example, 1 in version 1.5.1254.0 represents the major version, 5 represents the minor version, 1254 represents the build number, and 0 represents the revision number.

The version number is stored in the assembly manifest along with other identifying information, including the assembly name and public key, and information about the relationship and identity of other assemblies to which the application is connected.

When an assembly is generated, the development tool records the dependency information for each referenced assembly in the assembly manifest. The runtime uses these version numbers in conjunction with configuration information set by the administrator, application, or Publisher to load the correct version of the referenced assembly.

For versioning, the runtime distinguishes between regular assemblies and strong-named assemblies. Only version checks are performed on strong-named assemblies.

For information about specifying a version binding policy, see configuration files. For information about how the runtime uses version information to find specific assemblies, see how the Runtime Locates Assemblies.

Eight, what is managed code? What is unmanaged code?

Managed codes (managed code)
Code that is executed by the common language runtime environment, not directly by the operating system. Managed code applications can obtain common language runtime services, such as automatic garbage collection, runtime type checking, and security support. These services help provide platform-and language-independent, unified managed-code application behavior.
Managed code is code that can be written in more than 20 high-level languages that support the Microsoft. NET Framework, including: C #, J #, Microsoft Visual Basic. NET, Microsoft JScript. NET, and C + + 。 All languages share a uniform collection of class libraries and can be encoded as intermediate languages (IL). The runtime compiler (Runtime-aware Ompiler) compiles the intermediate language (IL) in the managed execution environment to make it locally executable code, and uses array bounds and index checking, exception handling, garbage collection, and other means to ensure type safety.

Using managed code in a managed execution environment and its compilation avoids many of the typical programming errors that lead to security black holes and unstable programs. Similarly, many unreliable designs are automatically enhanced with security, such as type safety checks, memory management, and the release of invalid objects. Programmers can devote more attention to the application logic design of the program and can reduce the amount of code written. This means shorter development times and more robust programs.

unmanaged (unmanaged code)

Code that is executed directly by the operating system outside of the common language runtime environment. Unmanaged code must provide its own garbage collection, type checking, security support, and other services, unlike managed code, which obtains these services from the common language runtime.

question: What is hosting? What does hosting mean?

Managed code, which is based on the. NET metadata format, runs on top of the. NET platform, and all of the exchange with the operating system has. NET to complete, like delegating these functions to. NET, so it's called managed code. Unmanaged code is the reverse.

An example L

Vc.net can also use Mfc,atl to write programs that are based on MFC or ATL rather than. NET, all unmanaged code, and managed code if. NET-based such as C#,vb.net

Unmanaged code refers to the. NET can't explain it.

Simply put, in the case of managed code,. NET can automatically release data, and unmanaged code needs to release the data manually.

Understanding of the. NET Platform

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.