Thursday, May 30, 2013

CLR (Common Language Runtime)

Common Language Runtime is the heart of .NET Framework used to manage the program written in .NET Framework compatible language (E.g. C#, Vb.NET, J# etc.). In other words, CLR is Execution Engine which executes the program for .NET Framework.
It provides a number of services, including the following:

ü  Code management (loading and execution)
ü  Application memory isolation
ü  Verification of type safety
ü  Conversion of IL to native code
ü  Access to metadata (enhanced type information)
ü  Managing memory for managed objects
ü  Enforcement of code access security
ü  Exception handling, including cross-language exceptions
ü  Interoperation between managed code, COM objects, and pre-existing DLLs
ü  Automation of object layout
ü  Support for developer services (profiling, debugging, and so on)


The Common Language Runtime (CLR) is the virtual machine component of Microsoft's .NET initiative. It is Microsoft's implementation of the Common Language Infrastructure (CLI) standard, which defines an execution environment for program code. The CLR runs a form of byte code called the Common Intermediate Language (CIL, previously known as MSIL (Microsoft Intermediate Language)


How CLR Works?


When we write a program in .NET compatible language, then the compiler for C# or VB.NET compiles the code in IL (Intermediate Language) or MSIL (Microsoft Intermediate Language) and then IL will be the input of CLR's component Just in Time compiler to produce machine independent code.
Apart from the above CLR is also responsible for:

Memory management

Thread management

Exception handling

Garbage collection

Security





Wednesday, May 29, 2013

CTS (Common Type System) & MSIL

Common Type System is the part of .NET Framework built in with CLR which is responsible for defining, managing different language's operation supported by .NET Framework. CTS are responsible for cross language Integration (Means you can have a dll which is written in C# and to be used in VB.Net application) and Type Safety. It enforces a set of rules that a programming language must follow.


Types of CTS (Common Type System)

The common type system supports two general categories of types:

1. Value types

Value types directly contain their data, and instances of value types are either allocated on the stack or allocated inline in a structure. Value types can be built-in, user-defined or enumerations types.

2. Reference types

Reference types stores a reference to the value's memory address, and are allocated on the heap. Reference types can be self-describing types, pointers types, or interface types. The type of a reference type can be determined from values of self-describing types. Self-describing types are further split into arrays and class types are user-defined classes, boxed value types, and delegates.



CTS, much like Java, define every data type as a Class. Every .NET compliant language must stick to this definition. Since CTS defines every data type as a class; this means that only Object-Oriented (or Object-Based) languages can achieve .NET compliance.


Microsoft Intermediate Language (MSIL)


A .NET programming language (C#, VB.NET, J# etc.) does not compile into executable code; instead it compiles into an intermediate code called Microsoft Intermediate Language (MSIL). As a programmer one need not worry about the syntax of MSIL - since our source code in automatically converted to MSIL. The MSIL code is then send to the CLR (Common Language Runtime) that converts the code to machine language which is then run on the host machine. MSIL is similar to Java Byte code. A Java program is compiled into Java Byte code (the .class file) by a Java compiler, the class file is then sent to JVM which converts it into the host machine language.

Tuesday, May 28, 2013

Common Language Specification (CLS)

One of the obvious themes of .NET is unification and interoperability between various programming languages. In order to achieve this; certain rules must be laid and all the languages must follow these rules. In other words we cannot have languages running around creating their own extensions and their own fancy new data types. CLS is the collection of the rules and constraints that every language (that seeks to achieve .NET compatibility) must follow.
The Common Language Specification is a set of basic language features (constructs and constraints) that serves as a guide for library writers and compiler writers. It allows libraries to be fully usable from any language supporting the CLS, and for those languages to integrate with each other. The Common Language Specification is a subset of the common type system. The CLS is actually a set of restrictions on the CTS. The CLS defines not only the types allowed in external calls, but the rules for using them, depending on the goal of the user.
Informally CLS is a simply a contract between programming language designers and class library authors. The CLS is basically just a subset of the entire set of features supported by the CLR. The CLS includes things such as calling virtual methods, overloading methods and does not include things such as unsigned types. CLS is weighted very heavily in favor of the library designers.
The Common Language Specification describes a common level of language functionality. The CLS is a set of rules that a language compiler must adhere to in order to create .NET applications that run in the CLR. Anyone who wants to write a .NET·-compliant compiler needs simply to adhere to these rules and that's it. The relatively high minimum bar of the CLS enables the creation of a club of CLS-compliant languages. Each member of this club enjoys dual benefits: complete access to .NET framework functionality and rich interoperability with other compliant languages. For example a VB class can inherit from a C# class and override its virtual methods.

The common language specification (CLS) is a collection of rules and restrictions that allow interoperation between languages. Even though the CLI does not require compilers to follow CLS, code that follows the CLS rules is compatible with all other languages that follow the CLS rules.
Microsoft has defined three level of CLS compatibility/compliance. The goals and objectives of each compliance level have been set aside. The three compliance levels with their brief description are given below:

  1. Compliant producer
The component developed in this type of language can be used by any other language.

  1. Consumer
The language in this category can use classes produced in any other language. In simple words this means that the language can instantiate classes developed in other language. 

  1. Extender
Languages in this category cannot just use the classes as in CONSUMER category; but can also extend classes using inheritance. Languages that come with Microsoft Visual Studio namely Visual C++, Visual Basic and C#; all satisfy the above three categories. Vendors can select any of the above categories as the targeted compliance level(s) for their languages.

Monday, May 27, 2013

UNIFIED CLASSES (Base Class Library)

The Unified Classes (Base Class Library) is a set of classes that provide useful functionality to CLR programmers. The .NET Framework class library exposes features of the runtime and simplifies the development of .NET-based applications. In addition, developers can extend classes by creating their own libraries of classes. All applications (Web, Windows, and XML Web services) access the same .NET Framework class libraries, which are held in namespaces. All .NET-based languages also access the same libraries.

The run time is responsible for managing your code and providing services to it while it executes, playing a role similar to that of the Visual Basic 6.0 run time.
The .NET programming languages including Visual Basic .NET, Microsoft Visual C# and C++ managed extensions and many other programming languages from various vendors utilize .NET services and features through a common set of unified classes.

The .NET unified classes provide foundation of which you build your applications, regardless of the language you use. Whether you simply concating a string, or building a windows Services or a multiple-tier web-based applications, you will be using these unified classes.
The unified classes provide a consistent method of accessing the platforms functionality. Once you learn to use the class library, you'll find that all tasks follow the same uniform architecture, you no longer need to learn and master different API architecture to write your applications.
By building your applications on a unified, integrated framework, you maximize your return on the time you spend learning this framework, and you end up with more robust applications that are easy to deploy and maintain.


Class Libraries

The .NET Framework has an extensive set of class libraries. This includes classes for:

• Data Access: High Performance data· access classes for connecting to SQL Server or any other OLEDB provider.
• XML Supports: Next generation XML support that goes far beyond the functionality of MSXML.
• Directory Services: Support for accessing Active directory/LDPA using ADSI.
• Regular Expression: Support for above and beyond that found in Perl 5.
• Queuing Supports: Provides a clean object-oriented set of classes for working with MSMQ.
These class libraries use the CLR base class libraries for common functionality.

Saturday, May 25, 2013

Introduction to .NET Framework

The .NET Framework is the heart of Microsoft .NET. The .NET Framework is a software development platform of Microsoft .NET. Like any platform, it provides a run-time, defines functionality in some libraries, and supports a set of programming languages. The .NET Framework provides the necessary compile-time and run-time foundation to build and run .NET-based applications.

Components of .NET Framework:


The .NET Framework consists of:

• Common Language Runtime
• Class Libraries
• Support for Multiple Programming Language


Application Development and Execution





  1. Developing application:
Since Microsoft .NET is a Multilingual platform then any.NET based language can be chosen to develop applications. Comfort ability of application programmers, specific requirement of applications may be the major factors in selection of language.


  1. Choosing a Compiler
According to the language we can choose its run time aware compiler for .NET platform. Because it is a Multilanguage execution environment, the runtime supports a wide variety of data types and language features.


  1. Compiling to MSIL
When compiling your source code, the compiler translates it into an intermediate code represented in Microsoft intermediate language (MSIL). Before code can be run, MSIL code must be converted to CPU-specific code, usually by a just-in-time (JIT) compiler. When a compiler produces MSIL, it also produces metadata. Metadata includes following information.
• Description of the types in your code, including the definition of each type,
• The signatures of each type's members,
• The members that your code references,
• Other data that the runtime uses at execution time.
The MSIL and metadata are contained in a portable executable (PE) file that is based on and extends the published Microsoft PE and common object file format (COFF) used historically for executable content. This file format, which accommodates MSIL or native code as well as metadata, enables the operating system to recognize common language runtime images.


  1. JIT Compilation to Native code:
The MSIL code is compiled into native code by component of CLR named JIT Compiler. JIT compiler intelligently guesses and compiles the intermediate code on piece by piece basis. This piece may be a method or a set of methods. Before a method can be run, it must be compiled to processor-specific code. Each method for which Microsoft intermediate language (MSIL) has been generated is just-in-time-compiled (JIT-compiled) when it is called for the first time, and then run. The next time the method is run, the existing JIT -compiled native code is run. The process of JIT -compiling and then executing the code is repeated until execution is complete.


  1. Type Safety Checking:
As part of compiling MSIL to native code, code must pass a verification process unless an administrator has established a security policy that allows code to bypass verification. Verification examines MSIL and metadata to find out whether the code is type safe, which means that it only accesses the memory locations it is authorized to access. Additionally, verification inspects code to determine whether the MSIL has been correctly generated, because incorrect MSIL can lead to a violation of the type safety rules. If type-safe code is required by security policy and the code does not pass verification, an exception is thrown when the code is run.


  1. Code execution under CLR:
The common language runtime is responsible for providing following low-level execution services, such as garbage collection, exception handling, security services, and runtime type safety checking. Because of the common language runtime's role in managing execution, programs that target the .NET Framework are sometimes called "managed" applications.


Features of .NET Framework

• It is a platform neutral framework.
• It is a layer between the operating system and the programming language.
• It supports many programming languages, including VB.NET, C# etc.
• .NET provides a common set of class libraries, which can be accessed from any .NET based programming language. There will not be separate set of classes and libraries for each language. If you know anyone .NET language, you can write code in any .NET language.
• In future versions of Windows, .NET will be freely distributed as part of operating system and users will never have to install .NET separately.

My First blog

Hello Developers,

This blog is for those who want to learn dot net framework and its languages. I'm dot net developer and I will try my best to give you specific content to understand the concepts. So, Keep visiting.
Happy Coding!

Cheers

Shrikant Joshi
Pune, Maharashtra