Exploring an Assembly Using ildasm.exe
The Intermediate Language Disassembler utility (ildasm.exe), which ships with the .NET Framework 4.0 SDK, allows you to load up any .NET assembly and investigate its contents, including the associated manifest, CIL code, and type metadata. By default, ildasm.exe should be installed under C:\Program Files\Microsoft SDKs\Windows\v7.0A\bin (if you cannot find ildasm.exe in this location, simply search your machine for a file named ildasm.exe).
NOTE
You can easily run ildasm.exe by opening a Visual Studio 2010 Command Prompt, and type "ildasm" (without the quotes) followed by the Enter key.
Once you run this tool, proceed to the File | Open menu command and navigate to an assembly you wish to explore. By way of illustration, here is the Calc.exeCalc.cs file shown earlier in this chapter (see Figure 1). ildasm.exe presents the structure of an assembly using a familiar tree-view format. assembly generated based on the
Figure 1. ildasm.exe allows you to see the CIL code, manifest, and metadata within a .NET assembly
1. Viewing CIL Code
In addition to showing the namespaces, types, and members contained in a given assembly, ildasm.exe also allows you to view the CIL instructions for a given member. For example, if you were to double-click the Main() method of the Program class, a separate window would display the underlying CIL (see Figure 2).
Figure 2. Viewing the underlying CIL
2. Viewing Type Metadata
If you wish to view the type metadata for the currently loaded assembly, press Ctrl+M. Figure 3 shows the metadata for the Calc.Add() method.
Figure 3. Viewing type metadata via ildasm.exe
3. Viewing Assembly Metadata (aka the Manifest)
Finally, if you are interested in viewing the contents of the assembly's manifest, simply double-click the MANIFEST icon (see Figure 4).
Figure 4. Viewing manifest data via ildasm.exe
To be sure, ildasm.exe has more options than shown here, and I will illustrate additional features of the tool where appropriate in the text.