Exploring .Net Assembly

Exploring an Assembly Using ildasm.exe
If you are beginning to feel a tad overwhelmed at the thought of gaining mastery over every namespace in the .NET platform, just remember that what makes a namespace unique is that it contains types that are somehow semantically related. Therefore, if you have no need for a user interface beyond a simple console application, you can forget all about the System.Windows.Forms, System.Windows, and System.Web namespaces (among others). If you are building a painting application, the database namespaces are most likely of little concern. Like any new set of prefabricated code, you learn as you go.

The Intermediate Language Disassembler utility (ildasm.exe), which ships with the .NET Framework 3.5 SDK, allows you to load up any .NET assembly and investigate its contents, including the associated manifest, CIL code, and type metadata. To load ildasm.exe, open a Visual Studio command prompt (using Start -> All Programs -> Microsoft Visual Studio 2008 -> Visual Studio Tools), type ildasm and press the Enter key.

Once you run this tool, proceed to the File -> Open menu command and navigate to an assembly you wish to explore. ildasm.exe presents the structure of an assembly using a familiar tree-view format.

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.

Viewing Type Metadata
If you wish to view the type metadata for the currently loaded assembly, press Ctrl+M.

Viewing Assembly Metadata (a.k.a. the Manifest)
Finally, if you are interested in viewing the contents of the assembly’s manifest, simply double-click the MANIFEST icon.


Exploring an Assembly Using Lutz Roeder’s Reflector
While using ildasm.exe is a very common task when you wish to dig into the guts of a .NET binary, the one gotcha is that you are only able to view the underlying CIL code, rather than looking at an assembly’s implementation using your managed language of choice. Thankfully, many .NET object browsers are available for download, including the very popular Reflector. This free tool can be downloaded from http://www.aisto.com/roeder/dotnet. Once you have unzipped the archive, you are able to run the tool and plug in any assembly you wish using the File -> Open menu option.

Notice that reflector.exe supports a Disassembler window (opened by pressing the spacebar) as well as a drop-down list box that allows you to view the underlying code base in your language of choice (including, of course, CIL code).

Source of Information : Apress Pro C Sharp 2008 and the dot .NET 3.5 Platform 4th Edition

0 comments


Subscribe to Developer Techno ?
Enter your email address:

Delivered by FeedBurner