【问题标题】:clrmd - Getting System.Runtime.InteropServices.SEHException After using DataTarget.CreateSnapshotAndAttachclrmd - 使用 DataTarget.CreateSnapshotAndAttach 后获取 System.Runtime.InteropServices.SEHException
【发布时间】:2020-01-09 14:07:49
【问题描述】:

我想通过使用clrmd API 来获取包含 c# 对象的大小。 为了获得这些信息,首先我需要附加到该过程。 为此,我使用DataTarget.CreateSnapshotAndAttach 方法。

由于某种原因,应用程序在收到System.Runtime.InteropServices.SEHException 异常后崩溃,错误代码为 0x80004005

堆栈跟踪:

   at Microsoft.Win32.SafeNativeMethods.CloseHandle(IntPtr handle)
   at Microsoft.Win32.SafeHandles.SafeProcessHandle.ReleaseHandle()
   at System.Runtime.InteropServices.SafeHandle.InternalFinalize()
   at System.Runtime.InteropServices.SafeHandle.Dispose(Boolean disposing)
   at System.Runtime.InteropServices.SafeHandle.Finalize()

此问题的根本原因是来自 GC 终结器线程的异常。

如何绕过或防止此异常?

完整代码示例:

public static void Main(string[] args)
{
    var processId = Process.GetCurrentProcess().Id;

    using (var dataTarget = DataTarget.CreateSnapshotAndAttach(processId))
    {
    }

    GC.Collect();
    GC.WaitForPendingFinalizers(); // Will cause exception
}

更新: 当我“不调试就开始”时,我没有得到异常。但我想调试。

【问题讨论】:

    标签: c# garbage-collection profiling clrmd


    【解决方案1】:

    clrmd 修复它并从版本 1.1.57604 开始支持它。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-12-25
      • 2019-06-03
      • 1970-01-01
      • 2012-10-20
      • 2013-12-22
      • 1970-01-01
      • 1970-01-01
      • 2014-08-30
      相关资源
      最近更新 更多