Join Ted Neward for an in-depth discussion in this video Ildasm, part of CLR Assemblies Deployment for .NET Developers.
- [Voiceover] Now one of the things I mentioned is that the assembly is actually this package, it's this collection of things, and, certainly, we could bring this up in some sort of binary editor, but that would show us a bunch of random hexadecimal values which wouldn't necessarily make a whole lot of sense. Microsoft develop, and this is a tool that has been available as a part of visual studio since the earliest days of the dot net betas. This utility called ildasm will actually allow us to interact with this compiled assembly, so if we say ildasm and then the name of the assembly itself, it's demonstrating what we see in an assembly, if we crack open the hood a little bit.
We see the manifest, and if we look at the manifest, we can see that this has, well, it's all basically gobbeldy gook for the moment, but this will all make more sense by the time we're done, I promise. We can see the assembly, Hello World, we can see some custom attributes, many of which we'll discuss in a little bit. We can see some version numbers, we can see some other things, here. And we can also see the structure of Hello World. Now remember, the code, the Hello World project is in the name space, Hello World here, and that will map directly over to this little blue shield, this is the name space icon inside of ildasm.
Now remember one of the concepts that I mentioned earlier is that assemblies are self descriptive, they contain all of the information regarding the thing that was built that they contain. And so here, we would expect, since Hello World we know contains one particular class, and going back to the code, we can see that that class is called program, and we can see that that program in turn contains a method called Main, then we should expect to see all of these elements present inside of that assembly. And sure enough, if we go back to ildasm, and we open up this node, so you can see here that this is the fully qualified class name, Hello World dot program, Hello World being the name space, and program being the class name.
And then, if we open that up in turn, we can see our main method here. Now, an important note is that there are no secrets, there's nothing hidden away from us as developers. You'll notice that there is another element here called dot ctor, and this is actually the default constructor that the C sharp compiler will synthesize for you if you do not provide a constructor. Now, you don't see that anywhere in the source code. Look, no constructor provided, again, because C sharp says every class must have a constructor, so, C sharp synthesized one for us by default.
There's also this little red triangle here which provides some class meta data about the class Hello World dot program. And in particular, it's a class, and it's hidden, and it's auto and ansi and beforefieldinit, all of these are hints to the CLR as to how to treat this particular class. All of this, by the way, is described in the CLR specification, which is an ECMA specification if you care to go look all of that up. But for the most part, this just basically describes the standard behavior we expect from a dot net application.
And remember that there's code in here, too, so if we, for example, double click on Main, we will see the il, the intermediate language, that the C sharp compiler translates your code into. So here we can see it's a method, it's static, it takes a string array. We can see some code here to load the constant string Hello World, and to call this method, and so on, and so on, and so on. All of this is what your C sharp code turned into. And this is basically the structure of your assembly.
- Reviewing the concept of assemblies
- Reviewing library assemblies in ildasm
- Working with assemblies and modules
- Working with assembly scope types
- Reviewing assembly names and versions
- Referencing assemblies from managed code