Techmentor

Techmentor
Techmentor

Wednesday, January 18, 2006

.NET Internals ...

.NET Framework:
The .NET framework allows objects, classes, and functions created in multiple programming languages the ability to communicate effectively amongst themselves. During code compilation within the .NET framework, source code is converted into MSIL (Microsoft Intermediate Language). MSIL, or IL, is the common language created that the CLR (Common Language Runtime) can read and understand. Once .NET code is compiled into the intermediate language (MSIL, IL), objects written in Visual Basic .NET may reference or inherit functionality from objects written in Visual C# .NET, managed Visual C++, or any other .NET language.

For each source code compiler (VB.NET, C#.NET, etc.), there is a minimum set of coding standards that must be met. The mininum set of coding standards that must be met to compile .NET code into MSIL code is known as CLS - Common Language Specification. The role of the Common Language Specification is to ensure that all generated code (MSIL) that meets the minimum set of coding standards can operate successfully within the .NET framework. THE CTS (Common Type System) handles conversion of programming-language data types into .NET compatible (MSIL) data types. The implicit benefit of the CTS is the reduction of development time when attempting to coordinate data types between two sets of different programming-language code.

Assembly and Assembly Manifest
The assembly is made up of code, metadata, and resources. The assembly manifest is a provider of information about the assembly. The information provided by the assembly manifest includes: assembly name, version number, identity information, types exposed by the assembly, list of other required assemblies, and a list of access security instructions and permissions regarding the assembly. The assembly manifest can be contained in its own file or within one of the assembly's modules. Each module can contain any number of combinations of two types: reference types (classes) and value types (structures). Type information is stored in the assembly manifest. Types can contain fields, properties and methods. A field represents storage of a particular type of data. A phone number can be stored to a field. Properties are very similiar to fields, but usually provide validation when data is set or retrieved. When an attempt to add or update a telephone number is made, validation to verify the telephone number has the proper number of characters may occur. Methods represent behavior. Continuing with the telephone example, you might have a Call method that communicates with a telephone and passes the telephone number as a parameter.

Compilation and Execution
A .NET application is not compiled to binary. As previously discussed, the .NET application code is compiled to MSIL. At least one of the MSIL assemblies will contain an executable that is designated as the application entry point. When execution begins, the first assembly is loaded and the CLR examines the assembly manifest and determines the program requirements. After a successful security permission check, the CLR will execute the code. During this period, a process for the application is created and application execution begins. When execution starts, the first bit of code that needs to be executed is loaded into memory and compiled into native binary code from IL by the CLR's Just-in-Time (JIT) compiler. Once compiled, the code is executed and stored in memory as native code. When program execution begins executing code that has not run, the JIT compiler compiles it ahead of execution and stores it in memory as binary code. Application performance is maximized because parts of a program that are executed are compiled.

No comments: