What is .Net Framework Explain

Net Framework is the first step to enter in to the .Net world. 
A framework can be defined as building blocks. Similarly .Net Framework can be defined as Building blocks of any .Net application.

The .Net framework contains set of assemblies (in .Net we call all the DLLs as Assemblies) to support different kind of .Net applications (may be windows based, web based and other applications). 


Depending upon the kind of application we would like to develop we can use the corresponding Assemblies available in the .Net Framework. 

.Net Framework also contains some Assemblies to execute the .Net application. 

So .Net Framework is the collection of Assemblies to support the .Net application development and .Net application execution.


The .Net framework mainly contains following components:


1. Common Language Runtime(CLR)

2. .Net Framework Class Library (FCL)
3. Common Type System(CTS):
4. Common Language Specification(CLS)

- It provides the necessary compile and run time foundation to build and run any language.


1. Common Language Runtime(CLR):


- It provides runtime environment.

- It runs all the .Net programs.
- The CLR provides memory management and thread management.
- It allocates the memory for scope and deallocates the memory.

2. .Net Framework Class Library(FCL):


- It accesses the library classes and methods.

- It is also called as Base Class Library.
- It is common for all types of application.

Following are the applications in .Net Class Library:


a. XML web services

b. Windows services
c. Windows application 
d. Web applications
e. Console application

3. Common Type System(CTS):


- CTS describes the set of datatypes which is used in different .Net languages.

- It ensures that objects are written in different .Net languages.

It supports two categories of types:


a. Value type:


- It is allocated on the stack or inline in a structure.

- It can be built-in types, user-defined or enumerations.

b. Reference type:


- It stores a reference to the value's memory address and allocated on the heap.

- It can be self-describing types, pointer types or interface types.

4. Common Language Specification(CLS):


- CLS specifies a set of rules.

- It is a subset of the CTS.
- CLS helps in cross language inheritance and debugging.

- CLS ensures that the products of compilers will work properly in .NET environment.



Components of .NET Framework 4.5 Architecture


  1. Common Language Runtime

    This acts as the execution engine for the .NET Framework. All .NET programs executes under the supervision of CLR.
  2. Base Class Library

    This is a library of functionalities which are available to all languages using the .NET Framework. It consists of classes, interfaces of reusable types that integrates with CLR
  3. Portable Class Library

    The Portable Class Library project in Visual Studio 2012 allows you to develop and build managed assemblies that work on multiple .NET Framework platforms. Using a Portable Class Library project, you choose the platforms (such as Windows Phone and .NET for Windows Store apps) to target.
  4. Managed Extensibility Framework (MEF)

    MEF is a library for creating lightweight, extensible applications. It allows application developers to discover and use extensions with no configuration required.
  5. Dynamic Language Runtime

    This provides the runtime environment for dynamic languages like python etc. for executing under the full control of CLR.
  6. WinRT

    WinRT or Windows Runtime APIs provides the user interface elements for building Windows Store apps, and provides access to Windows 8 or Windows RT OS features. WinRT supports development in C and other managed languages C# and VB.NET, as well as JavaScript and TypeScript.
  7. Asp.Net

    This is used to build rich internet based web application.
  8. Windows Store Apps (Metro Style Apps)

    A Windows Store app is a new type of application that runs on Windows 8 devices and can take advantage of new WinRT APIs. These can only be distributed in the Windows 8 store.
  9. Desktop Apps (Windows Forms)

    A Windows Desktop app is traditional Windows Forms application with a new name. Software developed for Windows XP, Windows Vista and Windows 7 will be categorized as a Windows Desktop app when running in Windows 8. Examples of Windows Desktop apps are Microsoft Office families products, notepad etc.
  10. WPF

    WPF is used to create applications with a rich user experience. It includes application UI, 2D graphics, 3D graphics and multimedia. It takes advantage of hardware acceleration of modern graphic cards. WPF makes the UI faster, scalable and resolution independent.
  11. Silver Light

    This is a cross-browser web based technology which allows designers and developers to deliver Rich Internet Applications (RIA) embedded in Web pages.
  12. Ado.Net

    This is used to create Data Access Layer to query and manipulate data from underlying data source like SQL Server, Oracle, and DB2 etc.
  13. LINQ

    This allows you to query the data from the various data sources (like SQL databases, XML documents, Ado.Net Datasets, Various Web services and any other objects such as Collections, Generics etc.) using a SQL Query like syntax with .Net framework languages like C# and VB.
  14. Ado.Net Entity Framework

    This is used to query and store data into to the relational databases (like SQL Server, Oracle, DB2 etc.) in ORM fashion.
  15. Parallel Extension

    This allows you to distribute your work code across multiple processors to take advantage of the hardware.
  16. WCF

    This is used for building and developing services based on WS-* standards.
  17. Asp.Net WebAPI

    Asp.Net Web API is a framework for building HTTP services that can be consume by a broad range of clients including browsers, mobiles, iphone and tablets.
  18. SignalR

    ASP.NET SignalR is a library that simplifies the process of adding real-time web functionality to applications. Real-time web functionality is the ability to have server code push content to connected clients instantly as it becomes available, rather than having the server wait for a client to request new data.
  19. WF

    This is used to build process oriented business workflow and rules engine.
  20. Visual Studio 2012

    The Visual Studio IDE offers a set of tools that help you to write and modify the code for your programs, and also detect and correct errors in your programs. Using Visual Studio 2012 you can build Windows Store apps, desktop apps, mobile apps, ASP.NET web apps, and web services.
Difference Between Finalize and Dispose Method
.Net Framework provides two methods Finalize and Dispose for releasing unmanaged resources like files, database connections, COM etc. This article helps you to understand the difference between Finalize and Dispose method.

Difference between Dispose & Finalize Method

Dispose
Finalize
It is used to free unmanaged resources like files, database connections etc. at any time.
It can be used to free unmanaged resources (when you implement it) like files, database connections etc. held by an object before that object is destroyed.
Explicitly, it is called by user code and the class which is implementing dispose method, must has to implement IDisposable interface.
Internally, it is called by Garbage Collector and cannot be called by user code.
It belongs to IDisposable interface.
It belongs to Object class.
It's implemented by implementing IDisposable interface Dispose() method.
It's implemented with the help of destructor in C++ & C#.
There is no performance costs associated with Dispose method.
There is performance costs associated with Finalize method since it doesn't clean the memory immediately and called by GC automatically.

Example for implementing the dispose method

  1. public class MyClass : IDisposable
  2. {
  3. private bool disposed = false;
  4. //Implement IDisposable.
  5. public void Dispose()
  6. {
  7. Dispose(true);
  8. GC.SuppressFinalize(this);
  9. }
  10.  
  11. protected virtual void Dispose(bool disposing)
  12. {
  13. if (!disposed)
  14. {
  15. if (disposing)
  16. {
  17. // TO DO: clean up managed objects
  18. }
  19. // TO DO: clean up unmanaged objects
  20.  
  21. disposed = true;
  22. }
  23. }
  24. }

Example for implementing Finalize method

If you want to implement Finalize method, it is recommended to use Finalize and Dispose method together as shown below:
  1. // Using Dispose and Finalize method together
  2. public class MyClass : IDisposable
  3. {
  4. private bool disposed = false;
  5. //Implement IDisposable.
  6. public void Dispose()
  7. {
  8. Dispose(true);
  9. GC.SuppressFinalize(this);
  10. }
  11.  
  12. protected virtual void Dispose(bool disposing)
  13. {
  14. if (!disposed)
  15. {
  16. if (disposing)
  17. {
  18. // TO DO: clean up managed objects
  19. }
  20. // TO DO: clean up unmanaged objects
  21. disposed = true;
  22. }
  23. }
  24. //At runtime C# destructor is automatically Converted to Finalize method
  25. ~MyClass()
  26. {
  27. Dispose(false);
  28. }
  29. }

Note

  1. It is always recommended to use Dispose method to clean unmanaged resources. You should not implement the Finalize method until it is extremely necessary.
  2. At runtime C#, C++ destructors are automatically Converted to Finalize method. But in VB.NET you need to override Finalize method, since it does not support destructor.
  3. You should not implement a Finalize method for managed objects, because the garbage collector cleans up managed resources automatically.
  4. A Dispose method should call the GC.SuppressFinalize() method for the object of a class which has destructor because it has already done the work to clean up the object, then it is not necessary for the garbage collector to call the object's Finalize method.


T stands for just-in-time compiler. It converts the MSIL code to CPU native code as it is needed during code execution. It is called just-in-time since it converts the MSIL code to CPU native code; when it is required within code execution otherwise it will not do nothing with that MSIL code.

Different Types of JIT


Pre-JIT COMPILER

Pre-JIT compiles complete source code into native code in a single compilation cycle. This is done at the time of deployment of the application.

Econo-JIT COMPILER:

Econo-JIT compiles only those methods that are called at runtime. However, these compiled methods are removed when they are not required.


 

Normal-JIT COMPILER:

Normal-JIT compiles only those methods that are called at runtime. These methods are compiled the first time they are called, and then they are stored in cache. When the same methods are called again, the compiled code from cache is used for execution.

These methods are compiled the first time they are called, and then they are stored in cache. When the same methods are called again, the compiled code from cache is used for execution.


NET supports two kind of coding

1) Managed Code
2) Unmanaged Code

Managed Code


The resource, which is with in your application domain is, managed code. The resources that are within domain are faster.

The code, which is developed in .NET framework, is known as managed code. This code is directly executed by CLR with help of managed code execution. Any language that is written in .NET Framework is managed code.

Managed code uses CLR which in turns looks after your applications by managing memory, handling security, allowing cross - language debugging, and so on.

managed_code.gif
 
Unmanaged Code

The code, which is developed outside .NET, Framework is known as unmanaged code.

Applications that do not run under the control of the CLR are said to be unmanaged, and certain languages such as C++ can be used to write such applications, which, for example, access low - level functions of the operating system. Background compatibility with code of VB, ASP and COM are examples of unmanaged code.

Unmanaged code can be unmanaged source code and unmanaged compile code.

Unmanaged code is executed with help of wrapper classes.

Wrapper classes are of two types: CCW (COM callable wrapper) and RCW (Runtime Callable Wrapper).

Wrapper is used to cover difference with the help of CCW and RCW.

COM callable wrapper unmanaged code


unmanaged_code_COM.gif

Runtime Callable Wrapper unmanaged code

unmanaged_code_RCW.gif

Native Code


The code to be executed must be converted into a language that the target operating system understands, known as native code. This conversion is called compiling code, an act that is performed by a compiler.

Under the .NET Framework, however, this is a two - stage process. With help of MSIL and JIT.

MSIL (Microsoft Intermediate Language)

It is language independent code. When you compile code that uses the .NET Framework library, you don't immediately create operating system - specific native code.

Instead, you compile your code into Microsoft Intermediate Language (MSIL) code. The MSIL code is not specific to any operating system or to any language.

DLL Hell


"DLL Hell" refers to the set of problems caused when multiple applications attempt to share a common component like a dynamic link library (DLL) or a Component Object Model (COM) class.

The reason for this issue was that the version information about the different components of an application was not recorded by the system. (Windows Registry cannot support the multiple versions of same COM component this is called the dll hell problem.)

.Net Framework provides operating systems with a Global Assembly Cache (GAC). This Cache is a repository for all the .Net components that are shared globally on a particular machine. When a .Net component is installed onto the machine, the Global Assembly Cache looks at its version, its public key, and its language information and creates a strong name for the component. The component is then registered in the repository and indexed by its strong name, so there is no confusion between different versions of the same component, or DLL.

Share this

Previous
Next Post »