Is it possible to get parameters' values for each frame in call stack in .NET

跟風遠走 提交于 2019-11-27 08:56:59

Parameters values aren't stored in StackFrame instance. In fact, they aren't recorded/logged at all, unless you choose to do it explicitly.

One obvious way to log theses values is to use AOP. It would certainly imply a cost, but in conjunction with a logging framework and the right log level, it may be an alternative. You could also choose to instrument only some types/methods in your basecode, where exceptions are more likely to be thrown. I would probably choose Postsharp for its static weaving capabilities, to emit log calls.

Anyway, it's far from being an ideal solution, but I'm afraid you won't have many options if you're stuck in the managed world.

Your best option is probably to insert the required trace code in the relevant methods. That way you can attach trace listeners and dump values when needed.

I know it is not what you're asking for, but it is one way to get the data.

Alternatively, you can debug the application using WinDbg. The !clstack/!dso commands will let you inspect parameters and stack objects.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!