Debugging issue (VS2010) when using dynamic keyword

220 views Asked by At

While debugging a compiler (mostly) written in C#, I noticed the following issue, which I tried to map to a simplified code fragment:

public class Program
{
    public abstract class Base
    {
        public abstract void foo();
    }

    public class A : Base
    {
        public override void foo()
        {
            Console.WriteLine("A");
        }
    }

    public class B : Base
    {
        public override void foo()
        {
            Console.WriteLine("B");
        }
    }

    public static void printOut(Base obj)
    {
        printOutImpl((dynamic)obj);
    }

    public static void printOutImpl(A aObj)
    {
        aObj.foo();
    }

    public static void printOutImpl(B bObj)
    {
        bObj.foo();
    }

    public static int Main(string[] args)
    {
        B bObj = new B();

        printOut(bObj);

        return 0;
    }
}

Basically, there are two implementations of printOut(..). The dynamic keyword is used to determine the corresponding implementation at runtime. When I'm debugging and try to step through the code, the debugger will not enter the corresponding printOutImpl(..) method unless there is a breakpoint set in the method body.

So my question is whether there is an option to disable/modify such behaviour. It's realy annoying to set (and remove) breakpoints to enforce the debugger to enter the method body.

Thanks! dinony

1

There are 1 answers

2
GM Lucid On

Use "step into"(F11) instead of "step over"(F10). I tested your code, and it correctly steps into printOutImpl(B bObj) and Console.WriteLine("B");