Exploring Assemblies with the Ildasm Utility


The .NET SDK ships with a built-in intermediate language disassembling utility program (ildasm.exe) that allows you to investigate the contents of any assembly in a simple, user-friendly GUI. This straightforward program gives you an overview of the namespaces, types, and type members of an assembly of your choice, along with the ability to scrutinize its intermediate language instructions and metadata.

You can start the ildasm application by typing the following after the command prompt:


You should then see an empty window appear called ILDASM. To choose the EXE or DLL assembly you want to inspect, click Open on the File menu. Use the File Open dialog box to navigate to the assembly of your choice. After you have located it, simply double-click its name.

If we choose to examine the Elevator.dll, we see a window somewhat similar to that shown in Figure 15.7, with a tree view of this assembly's structure. Each tree branch represents a part (namespace, class, method, property, or other) of the assembly and has an icon attached that tells us whether we are looking at a class, method, or something else. In our case, we see a cyan colored diamond displayed next to the Elevator.dll path and, further down, a blue shield (symbolizing a namespace) next to the familiar name of the namespace where the Sams.CSharpPrimerPlus.ElevatorSimulation.Elevator class resides. Expanding the namespace node reveals the content of this namespace the Sams.CSharpPrimerPlus.ElevatorSimulation.Elevator class and an associated blue rectangle with three connectors (symbolizing a class). To see the same tree view shown in Figure 15.7 you must also expand this class node. We can now recognize the name PrintClassName, which is Elevator's static method (symbolized by a magenta rectangle marked 'S'). A magenta rectangle without an S, such as that shown above PrintClassName, symbolizes a non-static method. ctor written next to the rectangle stands for constructor and represents the default constructor that was automatically generated by the C# compiler for the Elevator class because no explicit constructors were specified in the source code.

Figure 15.7. The ildasm window displaying the Elevator.dll assembly.

Notice the red right-pointing triangles next to MANIFEST and .class public auto ansi. This symbol signifies that more information (metadata) is held about a particular assembly or type. As we discussed in Chapter 2, the manifest holds information about the Elevator.dll assembly, and the red right-pointing triangle under the blue rectangle indicates that more information is held about the Elevator class.

By double-clicking any of the class members, another window appears containing the intermediate language instructions that the source code of this construct was turned into during its compilation. Useful information can be found by probing these more cryptic looking codes, but this discussion is beyond the scope this book.



To see the meaning of all symbols used in the tree view of the Ildasm, click Help on its Help menu and double-click the Tree View Icons item.

As a second Ildasm demonstration, we will take a brief look at the advanced mscorlib.dll that contains important System namespace. mscorlib.dll on my computer is located at C:\WINNT\Microsoft.NET\Framework\v1.0.2914\mscorlib.dll. You might have it on a disk drive other than C, and the version number (v1.0.2914) will likely, vary depending on the .NET SDK version you have installed. After you see its initial tree view in the Ildasm window, try to open the System namespace to expose the System.Collections namespace where the familiar ArrayList class resides. By expanding the System.Collections namespace node, you should see a window similar to that shown in Figure 15.8. Notice that the details in this window are likely to vary between different versions of the .NET SDK.

Figure 15.8. Ildasm displaying a tree view of mscorlib.dll.


C# Primer Plus
C Primer Plus (5th Edition)
ISBN: 0672326965
EAN: 2147483647
Year: 2000
Pages: 286
Authors: Stephen Prata

Similar book on Amazon

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net