Real World Computing
Assembling assemblies
Code: this is MS Interpreted Language (MSIL) code that implements the types defined in this assembly. MSIL code is compiled to native code by the Just-in-Time compiler whenever the application is run. As I'll be covering this in a future article, you can also use the ngen.exe utility to compile an assembly into native code that resides in the Global Assembly Cache (GAC).
There are broadly speaking two types of assembly: process assemblies and library assemblies. A process assembly, typically containing EXE files, represents a process that will use classes defined in library assemblies. Unlike Win32, .NET does not employ the filename extension to determine whether the file is a process or library, which means a library may have either a DLL or an EXE extension.
An assembly can be made up of one or more files, which may include multiple code files and a separate manifest. For example, an assembly might contain some executable code plus some resources such as JPEG and BMP image files. Since you can use different languages to create individual code modules under .NET, you could in theory combine several separately compiled code modules to create just one assembly, but in practice this doesn't happen, because Visual Studio only allows you to create an assembly made up of a single code module. If you build a .NET app, such as a console application or Windows app, you must have at least one assembly: your application. Your app may have functionality contained in separate DLLs - for performance reasons, to simplify development or for localisation - and in such cases you may have multiple assemblies to manage.
While I haven't talked about ASP.NET in much detail yet, assemblies are also used there. In the case of ASP.NET, you'll typically have an assembly for each page of your ASP.NET website, plus additional assemblies that perform common logic to be shared among the rest of the pages.
There are two tools you can use to look inside an assembly and view its contents, and it would be good idea to get both of them and start looking inside some assemblies to get acquainted. The first tool is Microsoft's Intermediate Language Dis-assembler, or ILDASM, contained in the .NET Software Development Kit (SDK), which you can download from msdn.microsoft.com. The second program is Reflector, a class browser for .NET components, which you can use to browse and search an assembly's metadata, IL instructions, resources and XML documentation. Written by Lutz Roeder, Reflector is a free download. For more information about the tool and to download a copy, see www.aisto.com
Building Assemblies
Building an assembly is generally done with one of the .NET language compilers, and to illustrate the concept of assemblies and how they work I've created two simple C# programs. The first is called Client (client.exe), which makes use of an external DLL to perform a calculation and print the results. Here's the source code for the client program:
using System;
public class Client
{
public static void Main()
{
Console.WriteLine("In Client.exe");
Maths m = new Maths();
long r1 = 2;
long r2 = 2;
long r = m.Add(r1, r2);
Console.WriteLine (" + = ", r1, r2, r);
}
}
The second component, maths.dll, implements the external Maths library use by client.exe, and its source looks like this.





