/// <summary> /// IBaseAdapter method: called when the test run is complete. /// </summary> void IBaseAdapter.Cleanup() { try { CleanupHostSide(); CleanupHostSession(); // Uninstall COM message filter. if (m_comMessageFilter != null) { m_comMessageFilter.Dispose(); m_comMessageFilter = null; } } finally { CleanupChannels(); } }
[SuppressMessage("Microsoft.Naming", "CA1725:ParameterNamesShouldMatchBaseDeclaration", MessageId = "0#")] // Base param name is incorrect. void ITestAdapter.Initialize(IRunContext runContext) { Debug.Assert(runContext != null); m_runContext = runContext; m_runConfig = m_runContext.RunConfig.TestRun.RunConfiguration; m_workingDir = m_runContext.RunContextVariables.GetStringValue("TestDeploymentDir"); Debug.Assert(m_runConfig != null); Debug.Assert(!string.IsNullOrEmpty(m_workingDir)); SetupChannels(); // TODO: consider more reliable mechanism for hadling VS being busy. Com message filter is only for STA/same thread. if (Thread.CurrentThread.GetApartmentState() == ApartmentState.STA) { // Install COM message filter to retry COM calls when VS IDE is busy, e.g. when getting the addin from VS IDE. // This prevents RPC_E_CALL_REJECTED error when VS IDE is busy. try { m_comMessageFilter = new RetryMessageFilter(); } catch (COMException ex) { string message = "Failed to create COM filter (ignorable): " + ex.ToString(); Debug.Fail(message); SendResult(ex.Message, TestOutcome.Warning, false); // Ignore the exception, continue without the filter. } } else { TraceMessage("COM message filter is disabled because it can be registered only in STA apartment, and current apartment is " + Thread.CurrentThread.GetApartmentState().ToString()); } InitHostSession(); }