Question

Consider following code:

public sealed class Program
{
    public static void Main()
    {
        System.Console.WriteLine("Hi");
    }
}

after compiling it with csc.exe, I've open the assembly using ILDasm and found something I couldn't figure out:

the ILDasm "Show!" command display only single TypeDef (the "Program" class) but at the statistics view I can see that the TypeDef count is 2.

Any idea where the second type came from?

Source: the book "CLR via C#" 3rd edition from Jeffrey Richter page 39.

Was it helpful?

Solution

Use View + MetaInfo + Raw:Header,Schema,Rows. You'll get a lot more detail in the Show! dump. You'll now see:

   1 == 0:00000000, 1:string#1, 2:string#0, 3:TypeDefOrRef[02000000], 4:Field[4000001], 5:Method[6000001]
   2 == 0:00100000, 1:string#22, 2:string#2a, 3:TypeDefOrRef[01000001], 4:Field[4000001], 5:Method[6000001]

Note the first one, token value 0. Just a dummy entry, it means "not a type". Doing it this way makes it easier on metadata parsers, that way any typeref token value has an entry in the table and there's no need to add tests for 0.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top