The .Net Framework and the Common Language Runtime

  • The Microsoft .NET Framework is a managed type-safe environment for application development and execution
  • The .NET Framework manages all aspects of your program’s execution
  • It allocates memory for the storage of data and instruction, grants or denies permission to your application, initiates and manages application execution, and manages the reallocation of memory from resources that are no longer needed
  • The .NET Framework consists of two main components: the Common Language Run time and the .NET Framework class library
  • The common language runtime can be thought of as the environment that manages code execution. It provides code services such as code compilation, memory allocation, thread management and garbage collection
  • Through the Common Type System (CTS), it enforces strict type safety and ensures that code is executed in a safe environment by enforcing code access security
  • The .NET Framework class library provides a collection of useful and reusable types that are designed to integrate with the common language run time. The types provided by the .NET Framework are object oriented and fully extensible, and they allow you to seamlessly integrate your applications with the .NET Framework


Languages and the .NET Framework
  • The .NET framework is designed for cross-language compatibility, which means simply, that .NET components can interact with each other no matter what supported language they were written in originally.
  • So, an application written in VB.NET might reference a dynamic link library (DLL) file written in Visual C#, which in turn may access a resource written in Visual C++ or any other .NET language.
  • This language interoperability extends to full object oriented inheritance. A Visual Basic.NET class might be derived from a C# class or vice versa
  • This level of cross language compatibility is possible because of the common language run time.
  • When a .NET application is compiled, it is converted from the language in which it was written (any of .NET compliance language) to Microsoft Intermediate Language (MSIL or IL)
  • MSIL is a low level language that the common language runtime can read and understand
  • Because all .NET executables and DLLs exist as MSIL, they can freely interoperate.
  • The Common Language Specification (CLS) defines the minimum standards to which .NET language compilers must conform
  • Thus, the CLS ensures that any source code successfully compiled by a .NET compiler can interoperate with the .NET Framework
  • The CLS ensures compatibility between .NET components. Because .NET applications are converted to IL prior to deployment and execution, all .NET data types are represented as .NET types.
  • Thus a VB.NET Integer and a C# int are both represented in IL code as a System.Int32.
  • Because both languages use a common type system, it is possible to transfer data between components and avoid time consuming conversion and hard to find errors
The Structure of a .NET Application
  • To understand how the common language run time manages code execution, we must examine the structure of a .NET application.
  • The primary unit of a .NET application is the assembly
  • An assembly is a self describing collection of code, resources, and metadata
  • The assembly manifest contains information about what is contained within the assembly
  • An assembly contains one or more modules
  • A module contains the code that makes up your application or library, and it contains metadata that describes that high level code to IL
Compilation and Execution of a .NET Application
  • When you compile a .NET application, it is not compiled to binary machine code, rather, it is converted to IL.
  • When execution of the program begins, the first assembly is loaded into the memory
  • At this point, the common language runtime examines the assembly manifest and determines the requirements to run the program
  • It examines the security permissions requested by the assembly and compares them with the system’s security policy
  • If the system’s security policy does not allow the requested permissions, the application will not run
  • If the application passes the system’s security policy, the common language runtime executes the code.
  • It creates a process for the application to run in and begins application execution
  • When execution starts, the first bit of code that needs to be loaded into the memory is compiled into native binary code from IL by the common language runtime’s Just-In-Time (JIT) compiler
  • Once compiled, the code is executed and stored in memory as native code
  • Thus, each portion of the code is compiled only once when an application executes
  • Whenever program execution branches to code that has not yet run, JIT compiler compiles it ahead of execution and stores it in memory as binary code
  • This way application performance is maximized because only the parts of a program that are executed are compiled

  • The .NET architecture is language neutral. As shown in the figure a C++ and a VB code can both be translated and assembled in an intermediate language. The .NET platform then will execute it.


Next >> The .NET Base Class Library


Our aim is to provide information to the knowledge


comments powered by Disqus










Footer1