是否可以反映正在运行的 .NET 进程?
我有一个在运行时发出动态类型的应用程序。为了检查生成的 .NET 代码,我们保存动态生成的程序集并使用 Reflector。
我想知道是否有一种方法可以在相应进程运行时以反射器方式反映它们,而不必保存动态程序集?换句话说,反射器中有一种“附加到进程...”按钮。
谢谢。
编辑:该功能的唯一存在理由是反映动态生成的程序集。
I have an application with dynamic types emitted at run-time. In order to inspect the generated .NET code, we save the dynamically generated assemblies and use the Reflector.
I am wondering whether there is a way to reflect them the Reflector way while the respective process is running, without having to save the dynamic assemblies? In other words to have sort of "Attach to process ..." button in Reflector.
Thanks.
EDIT: The only raison d'etre for the feature is to reflect on dynamically generated assemblies.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我知道您可能正在寻找来自动态程序集的 C# 代码,并且这个问题已经很老了,但是...
您可以使用 Visual Studio 立即窗口< 获取正在运行的动态程序集的 IL /strong> 或使用 WinDbg。 (如果您正在调试 64 位进程,则必须使用 WinDbg,因为 Visual Studio 仍然是 32 位产品。)
!load SOS.dll
加载SOS.dll或简单地!load SOS
。C:\Windows\Microsoft.NET\Framework64\v4.0.30319\SOS.dll
您可以在调试器中通过设置断点自动执行此操作,也可以在 VS 中通过弹出异常帮助程序自动执行此操作。
~
命令和~n s
命令手动选择线程。使用~
列出所有线程,使用~n s
命令进行切换。例如,使用~12 s
切换到线程号 12。!clrstack
!ip2md [地址]
0123456
,您将发出命令!ip2md 0123456
。!dumpil [方法描述符]
”列为方法描述符的地址,您将发出命令
!dumpil 0A1B2C3D`。这应该可以让您了解动态程序集,尽管是在 IL 程序集中。
I know that you are probably looking for C# code to come out of Dynamic Assemblies, and that this question is quite old, however...
You can get at the IL of a running dynamic assembly using the Visual Studio Immediate window or using WinDbg. (You must use WinDbg if you are debugging a 64-bit process, since Visual Studio is still a 32-bit product.)
!load SOS.dll
or simply!load SOS
.C:\Windows\Microsoft.NET\Framework64\v4.0.30319\SOS.dll
You can do this automatically in the either debugger by setting a breakpoint, or in VS by having the exception helper pop up.
~
command and the~n s
command. Use~
to list all threads and use~n s
command to switch. For example, use~12 s
to switch to thread number 12.!clrstack
!ip2md [address]
0123456
, you would issue the command!ip2md 0123456
.!dumpil [method descriptor]
as the address of the method descriptor, you would issue the command
!dumpil 0A1B2C3D`.That should allow you to see into the Dynamic Assembly, albeit in IL assembly.
Reflector 有一个正在运行的程序集插件 (http://weblogs.asp.net /kdente/articles/438539.aspx)。但是,我怀疑它只是帮助检索正在运行的程序集的路径,随后由 Reflector 从磁盘加载程序集。不过,这可能值得一试。此外,创建反射器加载项并不是那么困难,因此您也许能够扩展正在运行的程序集加载项方法,以自动将程序集保存到磁盘,以便可以通过反射器加载它(假设现有的加载项还没有这样做。)
There is a running assembly add-in for Reflector (http://weblogs.asp.net/kdente/articles/438539.aspx). However, I suspect that it simply helps retrieve paths for running assemblies, with the assemblies subsequently loaded from disk by Reflector. However, it's probably worth a try. Also, creating reflector add-ins isn't all that difficult, so you might be able to extend the running assembly add-in approach to automatically save the assembly to disk so that it can be loaded by Reflector (assuming the existing add-in doesn't already do this.)