Microsoft.Diagnostics.Runtime:如何读取崩溃转储

本文关键字:读取 崩溃 转储 何读取 Diagnostics Runtime Microsoft | 更新日期: 2023-09-27 18:19:47

我使用Microsoft.Diagnostics.Runtime并尝试分析崩溃转储,但我的机器上没有匹配的mscordacwks.dll

请给我一个建议,该怎么做,或者我如何从微软的符号服务器上获得它?

Microsoft.Diagnostics.Runtime:如何读取崩溃转储

丢失mscordacwks.dll是一件痛苦的事情,我经常使用WinDbg来查看崩溃转储文件(我注意到您正试图使用ClrMD来实现相同的最终目标)。通常,microsoft符号服务器是相当全面的,但在mscordacwks.dll的情况下,并非所有版本都存在于公共符号服务器上(如本文所述)。如果公共符号服务器出现故障,获取匹配的mscordacwks.dll版本的最佳方法是从创建崩溃转储的计算机(以及相应的.net框架文件夹)中提取它。

老实说,我更像是一个WinDbg用户,所以我更习惯于在那里处理mscordacwks,但从谷歌上环顾四周,我确实发现了一些有趣的文章。第一个提到你可以这样做:

// DataTarget.ClrVersions lists the versions of CLR loaded in the process (this may be
// v2 and v4 in the Side-By-Side case.
ClrInfo version = target.ClrVersions[0];
// CLRVersionInfo contains information on the correct Dac dll to load.  This includes
// the long named dac, the version of clr, etc.  This is enough information to request
// the dac from the symbol server (though we do not provide an API to do this).  Also,
// if the version you are debugging is actually installed on your machine, DacLocation
// will contain the full path to the dac.
string dacLocation = version.TryGetDacLocation();

如果这不起作用,有人发布了一个更复杂的DacLocator类的代码。希望这两种方法中的一种能够在您需要的dll版本中加载。

ClrVersion类上现在有一个TryDownloadDac方法。您需要在与正在调试的应用程序相同的体系结构(64位/32位)中运行进程,才能将DAC库成功加载到进程中。