Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why doesn't Visual Studio allow me to step into Type.GetType()?

I've got the following simple code:

class Program
{
    static void Main(string[] args)
    {
        var t = Type.GetType("System.Reflection.Assembly");

        Console.WriteLine(t.FullName);
    }
}

I'm attempting to debug into the Type.GetType() method, but the debugger skips over the method even when using "Step Into". I've got debugging enabled for the .NET Framework classes, and debugging into other framework methods works fine. Why doesn't the debugger allow me to step into this particular method?

like image 340
Mark Avatar asked Jul 20 '11 16:07

Mark


1 Answers

Because Type.GetType() is inlined to this:

[MethodImpl(MethodImplOptions.InternalCall), SecuritySafeCritical]
public extern Type GetType();

In other words, the method is implemented in C++ inside the CLR. The InternalCall attribute value is the key. Source code for the CLR is not available from the Reference Source. You could use the SSCLI20 source code for reference, it is a pretty good match for CLR source but you can't trust it to be completely accurate, it is no longer maintained. The clr/src/vm/ecall.cpp source code file contains the mappings from InternalCall names to C++ function names.

like image 90
Hans Passant Avatar answered Sep 17 '22 17:09

Hans Passant