Updated April 18, 2023
What is assembly?
Assembly is nothing but a collection of types and references that form logical unit of functionality. All types in asp.net framework must exist in assemblies; the common language runtime does not support types outside of assemblies. Assembly is automatically created when you create a Microsoft Windows application, windows service, or any class library. An assembly is stored as an .exe or .dll file.
Why do we need assembly?
The main goal of assembly is the elimination of DLL Hell. Under the current COM or COM+ model, a catalog of DLLs is centralized in the windows registry. When a new version of DLL is published, the registry re-references the catalog you point to the new DLl. This centralized registration paradigm makes it challenging for multiple applications to depend on the same DLL. Most often the application binds to a DLL in a centralized location, rather than run multiple versions of components by using side-by-side execution. The .net framework makes it easy to run multiple versions of components because it stores assemblies in local application directories by default. This isolate the assembly from use by any other application and protects the assembly from system changes.
Assembly Components
Components of assembly are as follows
- Assembly manifest: It is a section of the assembly which contains metadata about the assembly. It is considered as a header section of the assembly as it contains information like version number, publisher, information about encryption, etc. Assembly manifest can be stored in either a PF file i.e .exe or .dll with Microsoft Intermediate Language (MSIL) code or in standard PE file that contains only assembly manifest information.
- MSIL source code: MSIL contains information about initialization, loading, storing, and calling methods on objects. It also stores the instructions about the operation like arithmetic and logical operation, memory access, control flow, exception handling, etc. MSIL is platform-independent, which means source code of MSIL can be executed on any platform with .net framework support and JIT compiler. JIT compiler convert the code into machine-specific object code.
- Type metadata: Type metadata describes the format of contained types and external types referenced by the assembly. After executing the code, CLR loads the metadata into memory and drives the information about classes, attributes, their members, etc.
- Resources: .net framework consists of main assembly that contains various resources like sounds clips, string, images, and icons, etc.
Types of assembly
Based on the deployment processs of assembly, it is categorized into two categories, one is private assemblies and another is shared assemblies.
Private assemblies: It is also known as local assemblies. Private assembly is created when you make a class library to be used with your application and not designed to work with every .net application. Any application which is dependent on private assembly gets a local copy of the dll kept alongside the executables of the project in the bin folder of the project.
Shared assemblies: When you write a class library which could be used with any .net application on the system, it would be nice to have one common copy shared between all applications. This would update the assemblies easier. Such assemblies are known as global assemblies. They are kept on a standard location on the machine called as GAC. All .net framework assemblies are global and get installed in GAC when you install .net framework.
How does assembly works?
- Assembly contains code the common language runtime executes. MSIL code in PF file. i.e portable executable will not be executed if it does not have associated assembly manifest. Each assembly can have only one entry point.
- Assembly provides security as it is the unit at which permission are requested and granted.
- It forms deployment unit. When application starts, only the assemblies that the application initially calls must be present. Other assemblies such as localization resources or assemblies containing utility classes can be retrieved on demand. It allows the application to be kept simple and thin when first downloaded.
- It is the unit at which side-by-side execution is supported.
- Assembly provides boundary to type: Every type of identity includes the name of the assembly in which it resides. A type is called a type example, loaded in the scope of one assembly is no the same as type called type example loaded in the scope of another assembly.
- It forms a version boundary. Assembly ks the smallest versionable unit in the common language runtime. All types and resources in the same assemblies are versioned as. unit. The assembly manifest describes the version dependencies you specify for any dependent assemblies.
- Assembly provides boundary to the scope of assembly manifest contains assembly metadata that is used for resolving types and stratifying resource requests.
Conclusion
Here in this article, we have discussed the basic concepts of assembly with its components and types. We have also discussed the working of assemblies. Hope you enjoyed the article.
Recommended Articles
This is a guide to What is assembly?. Here we discuss Why do we need assembly? , Types of assembly, How does assembly works? respectively. You may also have a look at the following articles to learn more –