Assembly in .NET 2.0

Introduction

Before the .NET platform was introduced, we had to deal with the predecessors of assemblies: normal DLLs exporting global functions and COM DLLs exporting COM classes. Microsoft itself introduced the phrase DLL Hell to describe traditional problems with DLLs.

The answer to DLL Hell

The .NET platform's answer to DLL Hell and to all of its problems is Assemblies.

Assemblies are self-describing installation units, consisting of one or more files.

Features of assemblies

  1. Assemblies are self-describing.
  2. Version dependencies are recorded inside an assembly manifest.
  3. Assemblies can be loaded side-by-side.
  4. Application isolation is endured using application domains.
  5. Installation can be as easy as copying the files that belong to an assembly.
  6. Assemblies can be private or shared.

Assembly Structure

Component.dll

Assembly Metadata
Type Metadata
IL Code
Resources

In this example, the assembly metadata, type metadata, MSIL code, and resources are all in one file- Component.dll. The assembly consists of a single file.

Assembly Manifests

An important part of an assembly is manifest, which is part of the metadata. It describes the assembly with all the information that needed to reference it and lists all its dependencies.

Private and Shared Assemblies

A private assembly is found either in the same directory as the application, or within one of its subdirectories. With the private assembly, it is not necessary to think about naming conflicts with other classes or versioning problems. Private assemblies are the normal way to build assemblies, especially when applications and components are built within the same company.

While using shared assemblies, we have to be aware of some rules. The assembly must be unique and therefore must also have a unique name called a strong name. Shared assemblies will mostly be used when a vendor, different from that of the application, builds the component.

Creating modules and assemblies

Creating a module by using the command line c# compiler csc.

The command

csc /target:module hello.cs

creates a module hello. net module. we can view this module using ildasm.

We can compare modules to assemblies by creating a simple class A and compiling it by using the following command.

csc /target:module A.cs

Command to build an assembly B that includes the module A.netmodule.

csc /target:library/addmodule:A.netmodule /out:B.dll

Create a Strong name

A strong name is needed to share this assembly. We can create such a name with the strong name tool (sn):

Sn -k file.snk

The strong name utility generates and writes a public/private key pair, and writes this pair to a file; here the file is file.snk.

How to manage assemblies in Windows?

When we install .NET on our computer, some additional tools are installed in Windows to help us manage .NET and assemblies. We can find these tools by navigating from the Start button. Go to.

Control Panel > Performance and Maintenance > Administrative Tools > Microsoft .NET 2.0 Configuration

The tool helpfully checks to see if we have given the component a strong name before allowing the copy.

 Component


Similar Articles