Assemblies : The Ins and Out : Part I


This article is the first part of a three-part series of articles covering the .Net assemblies. In Part 1, I will cover what exactly an assembly is, and what an assembly contains. Part 2 of the series will discuss both Private and Shared assemblies and how to create a "Shared Assembly". I will briefly mention some of the utilities available for working with assemblies. Part 3 will discuss in more detail than Part 2, the details of the available utilities for manipulating assemblies.

What is a .NET Assembly?

An assembly is a core part of the runtime. An assembly is the collection of all information required by the runtime to execute your application. This information is referred to as the Metadata. An assembly can be a DLL file or a Portable Executable (PE) file. The Common Language Runtime (CLR) can only execute code in assemblies and the assembly must include a manifest or reference a manifest contained in another file.
An assembly that has been compiled into a portable executable (PE) file has an extension of AppName.exe. A common mistake made by newcomers to the .NET Framework is they think this *.exe file is the same as a standalone executable created by many other languages such as a C++ compiler. There are very big differences between a C++ executable file and a .NET PE file. The PE assembly consists of code in the form of Intermediate Language (IL). This IL code requires the .NET platform to be installed on the host in order to run.
What is the purpose of an Assembly?
An assembly controls many aspects of an application. The assembly handles versioning, type and class scope, security permissions, as well as other metadata including references to other assemblies and resources. The rules described in an assembly are enforced at runtime.

Contents of an Assembly

  • Manifest: The metadata describing the information below.
  • Assembly name: Aids in versioning and visibility scope.
  • Version information: The version number is integrated into the assembly's identity.
  • Types: Boundaries and scopes of methods, classes, properties, events, attributes.
  • Locale: Information describing language/culture. 
  • Cryptographic Hash: Public key encoded hash acting as version/security check. 
  • Security Permissions: The permissions within the assembly determine the permissions that can be granted for all aspects of the assembly contents.
The Assembly Menifest
All assemblies have a manifest. This manifest may be immediately contained within the assembly as in a single file assembly or may be referenced in a separate file as in multi-file assemblies.  The manifest contains information about all portions considered as part of the assembly itself. The information in the manifest is known as the Metadata. 
The manifest contains information that determines which components are visible beyond the assembly's namespace and also which components are to remain private to the assembly (Scope). 
Other optional information can be found in the manifest such as configuration information, information about your company, or copyright. 
The manifest contains so much information that usually an assembly can simply just be copied as a whole from one .NET framework to another without having to register with the destination operating system.
The Cryptographic Hash
This hash contains information such as references to all separate files that are referenced by the assembly, and references to other assemblies that are part of this assembly. The hash is encrypted using public key cryptography. This will be covered more in Part 2 of this article series. The hash is used at runtime to verify that all related files and assemblies have not been modified since the assembly was compiled. This helps prevent unwanted tampering. 

What is the Assembly Cache?

When the .NET SDK is installed, the framework creates a folder on the system. This folder is known as the Assembly Cache. The cache contains a Private section as well as a Global section. The global cache is home to assemblies that are shared. I will cover "Shared Assemblies in Part 2. Specific restricted files for an application may reside in the private section. Files that your application downloads at runtime are also stored in the private section of the cache. There are several utilities for working with assemblies and the cache area. These utilities are covered in the next series of articles (Part 2 -- 3).
All assemblies in the global cache must be shared and must contain unique namespaces. The folder names themselves contain part of the assembly's unique identity. The Assembly Cache can be found in your Windows directory in a subfolder called assembly. Check either C:\WINNT\Assembly or C:\Windows\assembly.
Continue Reading