次の両方のテストケースの実行後、COM実行がコンソールに出力されます。私は間違って何をしていますか?WPFによる終了時のCOM例外
テストを単独で実行する場合、または両方のテストを一緒に実行する場合、例外はコンソールに一度だけ書き込まれます。これは、私が掃除していないAppDomainリソースごとにいくつかの種類があることを疑うものです。
私はNUnitとMSTestで両方の環境で同じ動作をしてテストを試みました。 (実は、私は1つの例外プリントアウトまたは2でMSTestを結果の両方のテストを実行しているかはわからない。)
例外:
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();
}
}
}
たぶんhttp://social.msdn.microsoft.com/forums/en-US/vststest/thread/e53fdc45-23f3-4aee-aad9-f63769f2c638/は役立ちます –
悲しいことに、私はMTAを使用することはできません、 WPFにはSTAが必要です。 SetUpでフォームと要素のホストを作成しても、そのトリックは実行されません。アー。 –
もし私が間違っていないなら、この例外はユニットテストに失敗することはありませんか?私はWPFコントロールのunittesting中に同じ例外が発生しました。私はそれを無視するように選択しました;) – Bubblewrap