次の両方のテストケースを実行すると、COMの実行がコンソールに出力されます。私は何が間違っているのですか?
いずれかのテストを単独で実行する場合、または両方のテストを一緒に実行する場合、例外はコンソールに1回だけ書き込まれます。これにより、クリーンアップしていないAppDomainごとのリソースがあるのではないかと思われます。
NUnitとMSTestを使用してテストを試しましたが、両方の環境で同じ動作をしました。(実際、MSTestで両方のテストを実行すると、1つまたは2つの例外が出力されるかどうかはわかりません。)
例外:
System.Runtime.InteropServices.InvalidComObjectException: COM object that has been separated from its underlying RCW cannot be used.
at System.Windows.Input.TextServicesContext.StopTransitoryExtension()
at System.Windows.Input.TextServicesContext.Uninitialize(Boolean appDomainShutdown)
at System.Windows.Input.TextServicesContext.TextServicesContextShutDownListener.OnShutDown(Object target)
at MS.Internal.ShutDownListener.HandleShutDown(Object sender, EventArgs e)
テストコード:
using NUnit.Framework;
namespace TaskdockSidebarTests.Client
{
[TestFixture, RequiresSTA]
public class ElementHostRCWError
{
[Test]
public void WinForms()
{
var form = new System.Windows.Forms.Form();
var elementHost = new System.Windows.Forms.Integration.ElementHost();
form.Controls.Add(elementHost);
// If the form is not shown, the exception is not printed.
form.Show();
// These lines are optional. The exception is printed with or without
form.Close();
form.Controls.Remove(elementHost);
elementHost.Dispose();
form.Dispose();
}
[Test]
public void WPF()
{
var window = new Window();
// If the window is not shown, the exception is not printed.
window.Show();
window.Close();
}
}
}