If different executable code is running in the same process space, it is clear that they can easily share data because they can directly access each other's data. Although theoretically, it is feasible, but in actual conditions
CLR
You will check each running code to ensure that this situation does not happen, so that the code does not exceed the area you own. At first glance, it seems impossible, after all, if you don't actually run the code, how do you know how the code is running?
In fact, because IL has a powerful type security mechanism, this is possible. In most cases, unless code uses unsafe features, such as pointers, the data type ensures that memory will not be accessed. For example, the .NET array type performs a boundary check to ensure that any off -ral array operation is not allowed. If a running application does need to communicate or share data with another running application with different application domains, then it must be implemented by calling the remote service of the .NET.
This verification code is to ensure that the code cannot exceed the mechanism of application domain access data, called memory type security (different from the external remote call mechanism). This type of security code that is in a different application domain in a process is safe to run without interference.
1.3.3.3 Error by abnormal treatment
Like the exception handling mechanism used by Java and C , .NET Framework is also designed to adopt this convenient error-based error handling mechanism. C developers should notice that due to the same IL has a powerful input system, the use of exceptions in the same manner in IL and does not bring performance loss. .NET and C # also support a number of Finally blocks expected by many C developers.
We will discuss abnormalities in detail in Chapter 11. Simply put, the method of exception handling is specifying a piece of code as an exception handling routine to handle special exceptions, each piece of code can handle a specific error condition (for example, a file is not found, or some operations Refuse to execute). This particular error condition can be customized according to your needs, you can set a narrow condition can also be very wide. The abnormality processing architecture ensures that once there is an error condition, the program will immediately skip to execute the code block in the exception handling routine.
The abnormal processing architecture also provides a convenient way, you can pass an object that contains clear exception information to an exception handling routine. This object may contain a particular message of the user and the specific code to detect an exception.
When an abnormality occurs, most exception handling architecture, including program flow control, is processed by advanced language (e.g., C #, Visual Basic .NET, C ), not supported by any particular IL command. For example, C # utilizes code block try {}, catch {}, and finally {} (see Chapter 11).
However, .NET also does provide an infrastructure that allows all compilers that run the platform with .NET to support exception handling. In particular, .NET provides a collection of .NET classes to specifically represent abnormalities, and language interoperability allows exception handling code processing throwing exception objects, regardless of whether the code is written in writing. This language-independent is that the exception handling mechanism of C and Java cannot be implemented, but there is a certain embodiment of the incorrect handling mechanism of COM, which includes returning the error code from the method and transmitting the error object. The consistency of remained abnormal processing in different languages is a vital part of multilingual development.
1.3.3.4 Use of attributes
Developers who write COM components with C must be familiar with this feature (by them using Microsoft's Com Interface Definition Language [Idl]). Attribute initial intent is to provide additional information related to certain programs to the compiler. The attribute is supported by .NET, so now C , C #, and Visual Basic .NET are also supported. However, .NET's properties have innovative, that is, it provides a mechanism that allows you to define your own properties in your source code. These user-defined properties will be placed in the metadata corresponding to the data type or method. These metadata can be used for the preparation of documents, they can use the reflection technology to implement attribute-based execution design tasks. In addition, as in the principle of .NET language independent, it can be read in another language in the source code and read it in another language.
We will discuss attributes in Chapter 10.
1.4 assembly
A assembly is a logical unit that contains code compiled by .NET Framework. Here we don't want too much attention to the details of the assembly, because in Chapter 13, we will discuss in detail, but here summarize his points.
The assembly is completely self-description, and is a logical unit instead of physical, which means that he can store in not only one file (actually the dynamic assembly is stored in memory, not the file in). If an assembly is stored in multiple files, there will be a primary file containing the primary entry point and describes other files in the program.
It should be noted that the structure of their assembly is the same for executable code and library code. The only difference between them is that the program set of executable code contains a primary program export point, and the library code is not in the program set.
An important feature of the assembly allows it to include the types and method metadata defined in the corresponding code. However, an assembly also contains some description assemblies themselves. These include program collection data called an assembly list, which can be used to check the version information and integrity of the assembly.
Note: ILDASM, a Windows-based usage tool that can be used to check the contents of the assembly, including the list of assemblies, and metadata. We will discuss ILDASM in Chapter 13.
In fact, the program set contains the program's metadata means that the application or other assembly is called other code, with the information described in the assembly, there is no need to query the registry or other data source for how to use the assembly. . Relative to the old COM practice, this practice is a significant breakthrough. In previous old methods, the GUIDs and excuses of the components must be obtained from the registry, and in some cases, the details of the methods and properties need to be read from the type library.