tools/VsIdeHostAdapter/TargetAddIn/AgentSide/VsIdeHostAdapter.cs
/// <summary>
/// This should not throw.
/// We do the following steps. Each step is important and must be done whenever previous step throws or not.
/// - Call HostSide.Cleanup.
/// - Ask Runner IDE to detach debugger (if attached).
/// - Dispose m_vsIde.
/// </summary>
This should not throw.
We do the following steps. Each step is important and must be done whenever previous step throws or not.
This should not throw . We do the following steps . Each step is important and must be done whenever previous step throws or not .
[SuppressMessage("Microsoft.Design", "CA1031:DoNotCatchGeneralExceptionTypes")]
        private void CleanupHostSide()
        {
            if (!m_isHostSideDirty)
                return;
            lock (m_hostSideLock)
            {
                if (HostSide != null)
                {
                    try
                    {
                        ((ITestAdapter)HostSide).Cleanup();
                    }
                    catch (Exception ex)    
                    {
                        SendResult(Resources.FailedToCallTACleanup(ex), TestOutcome.Warning);
                    }
                }
                if (m_runConfig != null && m_runConfig.IsExecutedUnderDebugger)
                {
                    if (m_hostSession != null)
                    {
                        try
                        {
                            m_hostSession.DetachDebugger(m_vsIde.Process.Id);
                        }
                        catch (Exception ex)
                        {
                            SendResult(Resources.FailedToDetachDebugger(ex), TestOutcome.Warning);
                        }
                    }
                }
                if (m_vsIde != null)
                {
                    try
                    {
                        m_vsIde.Dispose();
                    }
                    catch (Exception ex)
                    {
                        SendResult(Resources.ErrorShuttingDownVS(ex), TestOutcome.Warning);
                    }
                }
                m_vsIde = null;
                m_hostSide = null;
                m_isHostSideDirty = false;
            }
        }
[ SuppressMessage ( " " , " " ) ] private void CleanupHostSide ( ) { if ( ! m_isHostSideDirty ) return ; lock ( m_hostSideLock ) { if ( HostSide != null ) { try { ( ( ITestAdapter ) HostSide ) . Cleanup ( ) ; } catch ( Exception ex ) { SendResult ( Resources . FailedToCallTACleanup ( ex ) , TestOutcome . Warning ) ; } } if ( m_runConfig != null && m_runConfig . IsExecutedUnderDebugger ) { if ( m_hostSession != null ) { try { m_hostSession . DetachDebugger ( m_vsIde . Process . Id ) ; } catch ( Exception ex ) { SendResult ( Resources . FailedToDetachDebugger ( ex ) , TestOutcome . Warning ) ; } } } if ( m_vsIde != null ) { try { m_vsIde . Dispose ( ) ; } catch ( Exception ex ) { SendResult ( Resources . ErrorShuttingDownVS ( ex ) , TestOutcome . Warning ) ; } } m_vsIde = null ; m_hostSide = null ; m_isHostSideDirty = false ; } }
This should not throw.
This should not throw .
//Debug.Assert(HostSide != null); // We don't know what this can throw in advance. // m_runConfig can be null if cleanup is called too early, i.e. before we completed init. // Detach debugger for VS we are going to shut down. //Debug.Assert(m_hostSession != null); // Detach debugger but keep HostSession alive for possible attach to restarted VS.