I am trying to get Visual Studio 2013 to programmatically attach the Debugger to a child process, which I start using the Process.Start
method.
Process.Start(ProcessStartupInformation startupInfo)
var subProcess = Process.Start(startInfo);
// TODO: how to find the right VS instance?
var dte2 = (EnvDTE80.DTE2)Marshal.GetActiveObject("VisualStudio.DTE.12.0");
var debugger2 = (EnvDTE80.Debugger2)dte2.Debugger;
Process2 processToAttachTo = null;
if (debugger2.LocalProcesses != null)
{
foreach (Process2 proc in debugger2.LocalProcesses)
{
if (proc.ProcessID == subProcess.Id)
{
processToAttachTo = proc;
}
}
}
if (processToAttachTo != null)
{
var trans = debugger2.Transports.Item("Default");
var engine1 = trans.Engines.Item("Managed (v4.5, v4.0)");
var engine2 = trans.Engines.Item("Native");
var engines = new[] { engine1, engine2 };
processToAttachTo.Attach2(engines);
}
Unfortunately, this seems to crash the Debugger. However, if I use only one of the engines
processToAttachTo.Attach2(engine1);
OR
processToAttachTo.Attach2(engine2);
everything works fine.
In that scenario, I can only debug either my C++ child processes or my C# child processes. But not both.
If I try to get processToAttachTo.Transport.Engines
and use those like so processToAttachTo.Attach2(processToAttachTo.Transport.Engines)
the Debugger crashes as well and I get at Call was rejected by callee. (Exception from HRESULT: 0x80010001 (RPC_E_CALL_REJECTED)) exception.
QUESTIONS:
Related Questions:
MessageFilter
when attaching to interop processesFurther info:
http://msdn.microsoft.com/en-us/library/ms228772(v=vs.120).aspx
A string[]
works for me (VS 2017):
processToAttachTo.Attach2(new string[] {"Managed (v4.5, v4.0)", "Native"});
User contributions licensed under CC BY-SA 3.0