views:

1114

answers:

3

What needs to be done to be able to step-into (F11) the reflected code.

I am creating the object using reflection:

myObject.GetType().GetConstructor().Invoke(myParams)

and I want to go into the constructor's code. If I press F11 it just skips the constructor's code ;(

but at the same time if I put a breakpoint at ctor and hit F5 - it will hit this breakpoint.

So, is there anything I can do to enable stepping into reflected code.

+1  A: 

I believe the issue is that there is technically no code to step into. Assuming you're dealing with a compiled module or library, you simply can't step into it since its compiled. Even if you're stepping into something you wrote, the object is being generated in memory so the compile probably has no concept of where those instructions are coming from anymore.

Soviut
I am not sure if we are talking about the same thing. I said - I could not step it to ctor's code, but I can get into this code if I just put and simple breakpoint and go debug (F5). So step in could be "emulated" by Visual Studio by implicitly addin breakpoint and F5-ing if VS detects what I am about to step-into MethodBase.Invoke (that should cover 50% reflection scenarious)
AlexKelos
A: 

What Soviut said: it's compiled code, you can't step into that. But I've seen this working when generating classes using CodeDOM and writing them to disk and CodeDOM compiling in Debug. Then you can step in the generated classes. But obviously that's a very specific case.

You might want to use Reflector to see what's going on in the constructor, but that's a static view of the situation.

Kurt Schelfthout
+4  A: 

Just My Code might be what is causing problems.

In Visual Studio:

  1. Tools --> Options
  2. Debugging (on the left)
  3. Untick "Enable Just My Code (Managed Only)" on the right.

I can't guarantee that is what is causing the problem - but it is my best bet.

Jonathan C Dickinson
Thanks Jonathan. That hit the bull's eye. Working. Fantastic. Thanks.
AlexKelos