Monday, January 17, 2011

.Net Assembly

Finally this is my first blog on my first love .Net.

Recently I interviewed some candidates. I asked few basic questions on .Net framework. I was not satisfied with their answer particularly for the answer of question what is .Net Assembly? So this is the blog about .Net Assembly.

One line definition of .Net Assembly is "It is the smallest deployable unit of .Net application" and here is the definition given on MSDN site

"Assemblies are the building blocks of .NET Framework applications; they form the fundamental unit of deployment, version control, reuse, activation scoping, and security permissions. An assembly is a collection of types and resources that are built to work together and form a logical unit of functionality. An assembly provides the common language runtime with the information it needs to be aware of type implementations. To the runtime, a type does not exist outside the context of an assembly."

So let's first understand why Microsoft has introduced the concept of Assembly with .Net Framework. What was wrong with previous approach?

Before .Net, applications were using standard DLLs and COM components. There might be the case that one DLL was shared between two or more applications. If one application updates the base DLL, other applications crashed because they can not understand the newer version. There was no facility to have more than one version of same DLL so applications using DLL can dynamically call the respective version they need. This situation coined a term called "DLL HELL".

So to resolve this issue Microsoft has introduced the the concept of .Net Assembly. As mentioned in the definition above it is the fundamental block of version control, now we have facility to specify the version information in line of code. Basically Assembly is nothing but your .Net application. If you are creating .Net class library, the DLL is your Assembly. If you are creating console application or windows application, the EXE file is your assembly. But it differs from the other executable files. It contains MSIL code and meta data which useful for CLR. Each assembly has one entry point like for DLL its DLLMain and for windows application its WinMain. In short your main function.

Each assembly has assembly manifest. It contains verious information about assembly like assembly version, culture etc. An executbale file without assembly manifest is called portable executable file.

Each assembly has version number associated with it to define its identity. Two assembly with different version number are treated as completely different assemblies by CLR. Version number are defined in four part as follow.

major-minor-buid-revision

For example 1.0.0.1

Major benefit of using assembly is we can achieve side by side execution. Side by side execution is the ability to use more than one version of same application on one computer. Version information can be stored in line of code. How to do it? I will publish another blog for it.

I hope this helps you.




No comments:

Post a Comment