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.
Best article!
How many types of assemblies in .net?What are they?
Not sure what you mean by “types of assemblies.” In .NET, an assembly can take the form of a dynamic link library (DLL) or an executable file (EXE).
Very simple yet clear to understand. Can u please post an article on how to create the multi file assembly with a small practical example.
Thanx you for the article.
All about assembly simply good.
quite gud but confused abt types of assemblies will u plz post
Three(3) types of assemblies:
1. Private
2. Shared
3. Resource
What makes it possible for more than one application using different versions of the same assembly to run at the same time? How does each application know which version to use? And why would there be multiple versions of the same assembly any way? I guess the bottom line is how are the applications and the assemblies linked? Or is the assembly a self-contained unit with the libraries needed included with application’s code?
Five(5) types of assemblies:
1. Single File
2. Multifile
3. Private
4. Shared
5. Sattelite
fantus article, best i had ever read. keep it up, god bless you.
if I have a solution with multiple projects and one of those projects (a schema holding project) holds about 3000 files what is the best way to break this up to decrease compile time. I’m currently trying to break the one schema project out to five project schema files ( based on business differences). I’m current using vs5 on XP – 32 bit. Is this the best way to go or is there a better way.
@Christian: 3000 files is a massive project! Not only is it unwieldly to manage and takes too long to compile, it’s probably rife with dependency issues.
Ideally the project should be subdivided into multiple smaller projects. Create a dependency tree to help guide you. Just like an inheritance tree, the project dependencies ideally should flow in a single direction (so there are no circular dependencies). Good luck!
Yeah 3000 files in one project is huge. This Application has more than 100 total projects. The specific project that holds 3000 files is basically holding (copybooks) datasets for transmitting data from the CICS server side DB2 storage to the desktop application and vice-verca.
The other 100 projects use the Schema project to access the dataset (particular data layout). If I break the 3000 files out to 6 different projects (based on different products) is there a way to access the different assemblies under on namespace. So, if the 6 new projects are called Project.Schema1, Project.Schema2…. etc… Can I access the 6 different schemas and there xsd’s using one namespace called “SCHEMA”. The xsd’s are unique.
@Christian: Yes, a single namespace can span across multiple assemblies. Of course you’ll want to ensure that you don’t have any duplicate type names or you’ll get an ambiguous definition error.
“The assembly manifest is required; the other elements are optional.”
Do you mean that the source code is not required?
Question: What are functions performed by an assembly?
A. It contains code that the CLR executes.
B. It forms a security boundary.
C. It’s the smallest unit of code.
D. It’s the unit at which side-by-side execution is supported.
E. It forms a version boundary.
Answer: ???
I m so confused that what is actually an assembly and what is the purpose of using assembly?can we create an assembly for an application?what is difference b/w assembly and namspace plz tell me??
The assembly is an important element of .NET programming. On the .NET platform, an assembly is a unit of reuse, versioning, security and deployment.an application, they must be placed into modules that are part of an assembly. Every managed application in .NET is deployed as an assembly. It means that the entire .NET code on compilation gets converted into an Intermediate Language (IL) code and gets stored as an assembly. In addition to the IL code, an assembly also contains Assembly metadata (Manifest), Type metadata and Resources.
If an assembly is to be made up of several programs, the programs can be stored in separate modules. Suppose there are two source files a.cs and b.cs of which, a.cs is stored in a module, whereas, ‘b.cs’ is stored in the assembly itself. Both comprise an assembly named mydll.dll.