我正在尝试将 ClrMD 附加到自身的进程中:
private static void Main()
{
var pid = Process.GetCurrentProcess().Id;
WriteLine($"PID: {pid}");
using (var dataTarget = DataTarget.AttachToProcess(pid, 1000))
{
WriteLine($"ClrMD attached");
}
}
但是,我收到以下异常:
PID: 7416
Unhandled Exception: Microsoft.Diagnostics.Runtime.ClrDiagnosticsException: Could not attach to pid 1CF8, HRESULT: 0x80070057
at Microsoft.Diagnostics.Runtime.DbgEngDataReader..ctor(Int32 pid, AttachFlag flags, UInt32 msecTimeout)
at Microsoft.Diagnostics.Runtime.DataTarget.AttachToProcess(Int32 pid, UInt32 msecTimeout, AttachFlag attachFlag)
at Microsoft.Diagnostics.Runtime.DataTarget.AttachToProcess(Int32 pid, UInt32 msecTimeout)
at BanksySan.Scratch.Console.Program.Main(String[] args)
我可以在被动模式下连接,但不能在侵入式或非侵入式模式下连接。