What are the different types of assemblies in .NET

There are three different types of assemblies in .NET:

Private Assemblies – Private Assemblies are normally used by a single application and is stored in the application's directory (the folder containing the application's executable file). Private Assemblies are deployed with the application and is available for the exclusive use of that application (they are not shared by other assemblies). Private assemblies must be designed to work side-by-side with other versions of the assembly on the system.

Private assemblies can be installed by any installation method that can copy the assembly's file into this folder, such as the xcopy command.

Note that the steps for creating a private assembly are identical to those for creating a shared assembly with two exceptions:
  • A private assembly is not required to be signed, and publickeyToken is not required in the assemblyIdentity element of the assembly manifest.
  • Private assemblies can be installed into the application's folder using any installation technology. Private assemblies are not required to be installed using the Windows Installer.
Public / Shared AssembliesShared Assemblies are available for use by multiple applications on the computer. They have version constraint and are stored in the Global Assembly Cache (GAC). GAC is the storehouse of public/shared assemblies and is maintained by the .NET runtime. A shared assembly must be strongly named.

Satellite Assemblies An assembly with culture information is automatically assumed to be a satellite assembly. These assemblies contain resource files pertaining to a locale (Culture+Language). These assemblies are used in deploying Global application for different languages.

Satellite assemblies are used to build multi-linguistic applications. These language-specific assemblies work in side-by-side execution because the application has a separate product ID for each language and installs satellite assemblies in a language-specific subdirectory for each language.


Satellite assemblies are not part of the main assembly. The resources of satellite assemblies that correspond to a specific culture can easily be updated or replaced without replacing the main assembly for the application.

What is an Assembly Manifest

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 MSIL code or in a standalone PE file that contains only assembly manifest information.

Functions of the Assembly Manifest
  • The manifest lists the files that make up the assembly.
  • It governs how references to the assembly's types and resources map to the files that contain their declarations and implementations.
  • It lists other assemblies on which the assembly depends.
  • It provides a level of indirection between consumers of the assembly and the assembly's implementation details.
  • It makes the assembly self-describing.

Contents of the Assembly Manifest

Given below are the details of the information contained in as Assembly Manifest:
  • Assembly Name – Name of the assembly.
  • Version numberA major and minor version number, and a revision and build number. The CLR uses these numbers to enforce version policy.
  • Culture – Information on the culture or language the assembly supports.
  • Strong name information – The public key from the publisher if the assembly has been given a strong name.
  • List of all files in the assembly - A hash of each file contained in the assembly and a file name.
  • Type reference information – Information used by the runtime to map a type reference to the file that contains its declaration and implementation. This is used for types that are exported from the assembly.
  • Information on referenced assemblies – A list of other assemblies that are statically referenced by the assembly. Each reference includes the dependent assembly's name, assembly metadata (version, culture, operating system, and so on), and public key, if the assembly is strong named.

Differentiate between Single-file assembly and Multifile assembly

When the components of an assembly is grouped in a single physical file, it is known as Single-file assembly.

When the components of an assembly is contained in several files, it is known as Multifile assembly. These files can be modules of compiled code (.netmodule), resources (such as .bmp or .jpg files), or other files required by the application. The files that make up a multifile assembly are not physically linked by the file system. Rather, they are linked through the assembly manifest and the CLR manages them as a unit.

Multifile assembly is usually created when there is a requirement to combine modules written in different languages and to optimize downloading an application by putting seldom used types in a module that is downloaded only when needed.

Components of an Assembly

There are four components of an assembly:
  • Assembly Manifest
  • Type Metadata
  • MSIL code
  • Resources
Out of the above four components, only assembly manifest is required. However, rest of the types or resources are needed to give the assembly any meaningful functionality.

Differentiate between Static and Dynamic Assemblies

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.

Dynamic Assemblies are run directly from memory and are not saved to disk before execution. However, dynamic assemblies can be saved to disk later, after they have executed. These binaries are created on the fly in the memory using SYSTEM.REFLECTION.EMIT namespace.

Assembly

An assembly as a collection of types and resources that form a logical unit of functionality. It is a fundamental unit deployment, version control, reuse, activation scoping, and security permissions for a .NET application. Assemblies are the building blocks of the .NET Framework and can take the form of an executable (.exe, also known as process assembly) file or dynamic link library (.dll, also known as library assembly) file. Assemblies are the smallest versionable unit in the CLR.

An assembly can contain one or more modules. Assemblies provide the CLR with the information it needs to be aware of type implementations.

Properties of an Assembly
  • An assembly is implemented as .exe or .dll file.
  • An assembly can be shared between applications by putting it in the Global Assembly Cache (GAC). Assemblies must be strong-named before they can be included in the Global Assembly Cache.
  • Information about an assembly can be obtained programmatically by using Reflection.
  • Assembly contains code that the CLR executes.
  • MSIL code in a portable executable (PE) file will not be executed if it does not have an associated assembly manifest.
  • Each assembly can have only one entry point (DllMain, WinMain, or Main).
  • An assembly is the unit at which permissions are requested and granted. Thus, it forms a Security Boundary.
  • It forms a Type Boundary. Every type's identity includes the name of the assembly in which it resides.
  • An assembly forms a Reference Scope Boundary. The assembly's manifest contains assembly metadata that is used for resolving types and satisfying resource requests. It specifies the types and resources that are exposed outside the assembly. The manifest also enumerates other assemblies on which it depends.
  • It forms a Version Boundary. The assembly is the smallest versionable unit in the CLR; all types and resources in the same assembly are versioned as a unit.
  • It forms 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.
  • It is the unit at which side-by-side execution is supported.