3

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

4
  • Hm, strange...I can reproduce the issue in VS2010, but I found a workaround: while debugging just before executing printOutImpl((dynamic)obj);, if I say to Step Into Specific > System.Action`3.Invoke, it works. Commented May 8, 2013 at 13:18
  • 1
    In VS2012 all work fine. Commented May 8, 2013 at 13:28
  • @Tim S: I tried it - For me the debugger jumps into disassembly: System.Dynamic.UpdateDelegates.UpdateAndExecuteVoid2. Commented May 8, 2013 at 13:40
  • @Vyacheslav Volkov: installed VS2012, working indeed. Thanks for both replies! Commented May 8, 2013 at 18:49

1 Answer 1

1

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");

Sign up to request clarification or add additional context in comments.

2 Comments

You're probably using Visual Studio 2012. In VS2010 "step into" does not work for me in that case. Also Tim S. could reproduce what I described. If your're really using VS2010 it would be cool to know your debug settings.
Compare your settings with mine. I'm using VS2010 Ultimate, by the way. Go to "Tools" -> "Import and Export Settings" -> "Export selected environment settings", and then mark only the "Options\Debugging" box. Here are my settings: pastebin.com/S91HkBt1

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.