I have a scenario where when I start debugging a silverlight OOB project in visual studio the debugger attaches to that automatically, but it doesn't attach to the iisexpress process which is running the web service that the silverlight application connects to. It does start iisexpress but doesn't attach to it automatically. I have to manually go to Debug->Attach to process, find iisexpress and attach to it to debug both client and serverside code.
Since VS2012 removed macros I can't use that to automatically attach, so I'm trying to create a simple add-in to do it instead.
I'm stuck on how to attach to the process though. I've tried the following methods which both fire at the right time and find the iisexpress process, but all 3 give exceptions when trying to attach to it. Can anybody suggest how I can do this?
private void DebuggerEventsOnOnEnterRunMode(dbgEventReason reason)
{
if (reason == dbgEventReason.dbgEventReasonLaunchProgram)
{
foreach (Process process in _applicationObject.Debugger.LocalProcesses)
{
var nameparts = process.Name.Split(Path.DirectorySeparatorChar);
string name = nameparts[nameparts.Length - 1];
if (name.Contains("iisexpress"))
process.Attach();
// also tried: _applicationObject.ExecuteCommand("Debug.AttachToProcess", process.Name);
// and: _applicationObject.ExecuteCommand("Debug.AttachToProcess", name);
}
}
}