Wednesday, October 01, 2008

Assemblies in .Net

Assemblies
Assemblies are the building blocks of .NET Framework applications which form the fundamental unit of deployment, versioning, 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.
Each time you create a Microsoft Windows Application, Windows Service, Class Library, or other application with Visual Basic .NET, you're building a single assembly. Each assembly is stored as an .exe or .dll file.
An assembly performs the following functions:

1. It contains code that the common language runtime executes. MSIL code will not be executed if it does not have an associated assembly manifest.

2. A security boundary : An assembly is the unit at which permissions are requested and granted.

3. A type boundary : Every type's identity includes the name of the assembly in which it resides.

4. A reference scope boundary : The assembly's manifest contains assembly metadata that is used for resolving types and satisfying resource requests.

5. A version boundary : The assembly is the smallest versionable unit in the common language runtime. All types and resources in the same assembly are versioned as a unit. The assembly's manifest describes the version dependencies you specify for any dependent assemblies.

6. A deployment unit : When an 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.7.Assembly support side-by-side execution.

Assemblies can be static or dynamic. Static assemblies can include .NET Framework types (interfaces and classes), as well as resources for the assembly (bitmaps, JPEG files, resource files, and so on). Static assemblies are stored on disk in portable executable (PE) files. .NET Framework also create dynamic assemblies, which run directly from memory and are not saved to disk before execution. Dynamic assemblies can be saved to disk after execution.

Assembly Benefits
Assemblies are designed to simplify application deployment and to solve versioning problems that can occur with component-based applications. They are self-describing components having no dependencies on registry entries. So assemblies enable zero-impact application installation. They also simplify uninstalling and replicating applications.

Assembly Contents
In general, an assembly can contain :
1. Assembly manifest
2. Type metadata
3. Microsoft intermediate language (MSIL)
4. A set of resources

Assembly Manifest
Assembly manifest is assembly metadata which contains a collection of data that describes how the elements in the assembly relate to each other. An assembly manifest contains all the metadata needed to specify the assembly's version requirements and security identity, and all metadata needed to define the scope of the assembly and resolve references to resources and classes. The assembly manifest can be stored in either a PE file (an .exe or .dll) with Microsoft intermediate language (MSIL) code or in a standalone PE file that contains only assembly manifest information.

In a single-file assembly, the manifest is incorporated into the PE file.A multifile assembly can be with a standalone manifest file or with the manifest incorporated into one of the PE files in the assembly.

Information contained in the assembly manifest :
1. The assembly name and version
2. The culture or language the assembly supports.
3. The public key for any strong name assigned to the assembly
4. A list of files in the assembly with hash information
5. Type reference information : Information used by the runtime to map a type reference to the file that contains its declaration and implementation.
6. Information on referenced assemblies : A list of other assemblies that are referenced by the assembly.

No comments: