依恋ClrMD?结果:0x80070057 [英] Attach to self with ClrMD? HRESULT: 0x80070057

查看:141
本文介绍了依恋ClrMD?结果:0x80070057的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将一个过程中的ClrMD附加到其自身上:

I'm trying to attach the ClrMD in a process to itself:

private static void Main()
{
    var pid = Process.GetCurrentProcess().Id;

    WriteLine($"PID: {pid}");
    using (var dataTarget = DataTarget.AttachToProcess(pid, 1000))
    {
        WriteLine($"ClrMD attached");
    }
}

但是,我遇到以下异常:

However, I'm getting the following exception:

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)

可以以被动模式连接,但不能以侵入或非侵入模式连接.

I can attach in passive mode, but not in Invasive or Non-Invasive mode.

推荐答案

您可以使用DataTarget.CreateSnapshotAndAttach. 此方法创建该过程的快照并从中创建DataTarget. 示例:

You can use DataTarget.CreateSnapshotAndAttach. This method creates a snapshot of the process and create DataTarget from it. Example:

var processId = Process.GetCurrentProcess().Id;

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

这篇关于依恋ClrMD?结果:0x80070057的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆