Frequently asked questions, some assembly required.
This multi-part article answers common questions about assemblies–the basic building blocks of .NET applications. Some developers may never need to understand assemblies. But if you create shared components, use DLLs or deliver a suite of applications, then it’s essential to understand what .NET assemblies are and how they work.
What is a .NET assembly?
An assembly is the primary building block of a .NET application and can take the form of a dynamic link library (DLL) or executable file (EXE). An assembly is a collection of functionality that is built, versioned, and deployed as a single implementation unit.
What does an assembly contain?
A .NET assembly may contain the following elements:
- Assembly Manifest – Metadata that describes the assembly and its contents (see below)
- Source Code – Compiled into Microsoft intermediate language (MSIL)
- Type Metadata – Defines all types, their properties and methods, and most importantly, public types exported from this assembly
- Resources – Icons, images, text strings and other resources
The assembly manifest is required; the other elements are optional.
What is an assembly manifest?
An assembly manifest is metadata inside an assembly that describes everything there is to know about the assembly and its contents. The manifest contains:
- Strong Name – The assembly’s name, version, culture, optional processor architecture, and public key (for shared assemblies)
- File Contents – Name and hash of all files in the assembly
- Type List - Types defined in the assembly, including public types that are exported from the assembly
- Resource List – Icons, images, text strings and other resources contained in the assembly
- Dependencies – Compile-time dependencies on other assemblies
- Security – Permissions required for the assembly to run properly
What is a multi-file assembly?
An assembly can consist of one or more files called modules. Exactly one of these modules contains the assembly manifest. Note that the files in a multi-file assembly can reside in separate locations and are linked together with the assembly manifest.
Multi-file assemblies are rare, and Visual Studio doesn’t directly support their creation. The most common reason for multi-file assemblies is when a single assembly combines code from multiple programming languages. (more)
What is the difference between a private and shared assembly?
A private assembly is used only by a single application and is stored in that application’s installation folder (or subfolder therein). The name of a private assembly name must be unique within the application that uses it.
A shared assembly is used by multiple applications and is typically stored in a global folder known as the Global Assembly Cache (GAC). When building an assembly, a developer must specifically choose to build it as a shared assembly by giving it a cryptographically strong name. For example, the .NET Framework is a collection of shared assemblies.
What is the difference between an assembly and a namespace?
Namespaces are logical, whereas assemblies are physical.
A namespace is a logical naming scheme to group related types. Namespaces can contain other namespaces to form a hierarchy. The “fully qualified name” of a type is its namespace followed by its type name, separated by a period (for example, System.Windows.Forms.Button). Type names must be unique within a namespace, but the same type name can be used in different namespaces.
An assembly is a physical deployment scheme to group related types. An assembly can contain one or many namespaces. A namespace can exist in one or many assemblies.