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);
}
}
}
Works for both VS 2010 & VS 2012:
Solution -> Right Click -> Set Startup Projects -> Multiple Startup Projects
Choose your 2 projects and under action set it to Start other than (for the 2nd project) possible Start Without Debugging.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With