Sau khi thực hiện cả hai trường hợp kiểm tra sau, thao tác COM được in trên bảng điều khiển. Tôi đang làm gì sai?ngoại lệ COM khi thoát với WPF
Nếu tôi chạy thử nghiệm đơn lẻ hoặc nếu tôi chạy cả hai kiểm tra cùng nhau, ngoại lệ được ghi vào bảng điều khiển chính xác một lần. Điều này khiến tôi nghi ngờ rằng có một số loại tài nguyên trên mỗi AppDomain mà tôi không dọn dẹp.
Tôi đã thử các thử nghiệm với NUnit và với MSTest, với cùng một hành vi trong cả hai môi trường. (Trên thực tế, tôi không chắc chắn nếu chạy cả hai bài thi trong kết quả MSTest trong một ngoại lệ hoặc hai bản in duy nhất.)
Ngoại lệ:
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)
mã kiểm tra:
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();
}
}
}
lẽ http://social.msdn.microsoft.com/forums/en-US/vststest/thread/e53fdc45-23f3-4aee-aad9-f63769f2c638/ giúp –
Đáng buồn thay, tôi không thể sử dụng MTA, vì WPF yêu cầu STA. Tạo ra các hình thức và máy chủ yếu tố trong SetUp dường như không làm các trick, một trong hai. Argh. –
Nếu tôi không nhầm, ngoại lệ này không gây ra lỗi không nhất thiết, phải không? Tôi đã gặp phải ngoại lệ tương tự trong khi unittesting điều khiển WPF của tôi, tôi đã chọn để bỏ qua nó ..;) – Bubblewrap