CLR gives very strong guarantees regarding stacks. Necessarily so, they are very important to make a garbage collector and secure access to the code. What you cannot count on, however, is that GetFrame (0) gives you the stack stack of your method. Invalid code is an important jitter optimization. At least not without explicit suppression of optimization using [MethodImpl], pointing MethodImplOptions.NoInlining to your method.
Both stacks and suppression of road optimization, so make sure this code is not in your critical path.
Compiler support for this function will be added to the next version of C # version 5 with the attribute [CallerMemberName] .
source share