Question

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);
        }
    }
}
Was it helpful?

Solution

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top