What is Assembly in .NET Framework

An Assembly is an logical unit tht consists programs and libraries.An Assembly contains a self describing binary file which can be either Dynamic Link Library (DLL) or Executable file that is EXE.
An Assembly also contains a collection of Types such as Classes,Interfaces,and Structures.A single Assembly can contain multiple code files or a singlr code file can have more than one Assembly.
Assemblies can be of two types.
Static Assembly
Dynamic Assembly.
Static Assemblies includes Interfaces,Classes and Resources .These assemblies are stored in the Portable Executable file on a disk.
Dynamic Assemblies is run directly from the memory without being saved to disk before execution. However after execution you can have save them on the disk.
Assembly Contents An Assembly is a logical unit that consists of four elements - The Manifest, Type Metadata,IL Code that implements the types and a set of resources.These elements can be grouped in the form of a single file or a collection of multiple files.

Assembly Manifest

Assembly Manifest is a file that contains the metadata of the assembly ,which is the information of version requirements and security identity of the assembly and describes the relations between all the elements in that assembly.The manifest can be stored either in a Portable Executable file with IL code or in a standalone Portable Executable file that contains only the manifest information.
Information stored in the assembly manifest is like
The information in the assembly manifest can be modified by using the assembly attributes.

  • Assembly Name
  • Version Number
  • Culture
  • Strong Name information.
  • List of all files in Assembly.
  • Type reference information.
  • Information on referenced assemblies.

What is Metadata ?

A Metadata is the self description of a program in the binary format.Metadata contains the information of the Classes,Methods,and other elements used in a program.This information is stored in a CLR Portable Executable file or in the Memory.
The Metadata describes every data type and member of your program. When the code is in the run mode the CLR loads the Metadata into the Memory and finds information about the Classes and Members.
The Metadata of a program includes :-
1.Assembly Information such as Name of Assembly ,Version,Culture,Public Key,the types of Assemblies other referenced assemblies and security permissions.
2.Information about types such as Name,Visibility,BaseClass,Interfaces used and members.
3.Attributes information that modifies the types and members of a class.
After providing this information CLR is able to create Objects,access data and call member functions.

What is GAC that is Global Assembly Cache ?

GAC is the Machine wide code Cache in a computer which is the center place for registering assemblies. Assemblies must be made sharable by registering them in the Global Assembly Cache only when needed otherwise they must be kept Private.
It is not mandatory to install the assemblies in the GAC ,in order to make them accessible to the COM interOp or unmanaged code.
The Com interOp is a service that enables .NET Framework objects to communicate with Com Objects.We can deploy an Assembly in the GAC using any one of the following
1. An installer that is designed to work with GAC.
2. The GAC Tool known as Gacutil.exe .
3. The windows explorer to drag assemblies into the Cache.

What is Strong Name Assembly ?

A Strong Name Assembly is a hash token that contain the assembly's identity that is the information about the Assembly's Name Version Number,Culture,Public Key and digital signature. Using the private key manifest generates the strong name.
You can provide a strong name to an assembly using the MS Studio .NET and other development tools.
Using strong name for assemblies has the following benefits.
1.Provides Uniqueness to the names by generating a private key.
2.Ensures that the version of the assembly you are using comes from the same publisher who has created the version the application was built with.
3.Ensure that the contents of the assembly do not change since its last build.

What is Private and Shared Assemblies ?

Private Assembly :- An Assembly is called a Private Assembly if it is used by only a single application.
If you have created DLL containing information about your business logic ,then this DLL can be used by your client application only.
In order to run the application the DLL must be included in the same folder in which the client application has been installed. This makes assembly private to your application.
Shared Assembly :- Shared Assemblies are those assemblies that are placed in the Global Assembly Cache so that yhey can be used by multiple applications. Consider a scenario where the DLL needs to be reused in different applications.In this case,instead of transferring a copy of the DLL at each and every client application,the DLL can be directly placed in the GAC by using the GACUTIL.exe tool from where the DLL application can be accessed by any client application.

Image is not available

About the Author
Sudheer Singh Chouhan is a Software Engineer having Expertise in Development Design and Architecting the applications , Project Management , Designing Large Scale Databases in SQL Server since last 17 Years.
Skill Sets :- Microsoft .NET technologies like ASP.Net Core, Web API, LINQ, Web Forms, WinForms, SQL Server, EntityFramework, Design Patterns, Solid Principles, Microservices, AWS Cloud.