C# Nunit 3.12.0在WPF视图模型单元测试中缺少[RequirestTA]。调用线程必须是STA

C# Nunit 3.12.0在WPF视图模型单元测试中缺少[RequirestTA]。调用线程必须是STA,c#,.net,wpf,nunit,C#,.net,Wpf,Nunit,将Nunit从v2.6.3版更新到3.12.0版后。我的部队停止通过。 此问题发生在单元测试中,更新后找不到RequireStatAttribute [Test] [RequiresSTA] public void When_Smart_Motion_Activity_Is_Selected_The_Values_Are_Valid() { SomeViewModel vm = ViewModelHelper.CreateDefaultViewModel(); ... }

将Nunit从v2.6.3版更新到3.12.0版后。我的部队停止通过。 此问题发生在单元测试中,更新后找不到RequireStatAttribute

[Test]
[RequiresSTA]
public void When_Smart_Motion_Activity_Is_Selected_The_Values_Are_Valid()
{
     SomeViewModel vm = ViewModelHelper.CreateDefaultViewModel();
     ...
}
移除属性后,测试失败,出现以下异常:

System.InvalidOperationException:调用线程必须是STA, 因为许多UI组件都需要这样做。在 System.Windows.Input.InputManager..ctor位于 System.Windows.Input.InputManager.GetCurrentInputManagerImpl位于 System.Windows.Input.KeyboardNavigation..ctor位于 System.Windows.FrameworkElement.FrameworkServices..ctor位于 System.Windows.FrameworkElement.EnsureReframeWorkservices位于 System.Windows.FrameworkElement..ctor位于 System.Windows.Controls.Panel..ctor位于 System.Windows.Controls.Canvas..ctor位于项目….:线xyz

对于适用于3.12.0的[RequirestTA],是否有任何建议的解决方法或替代方法?

您可以使用:

[Test]
[Apartment(ApartmentState.STA)]
public void When_Smart_Motion_Activity_Is_Selected_The_Values_Are_Valid()
{
     SomeViewModel vm = ViewModelHelper.CreateDefaultViewModel();
     ...
}

作为解决办法,我添加了一个新项目。现在我有了带有旧单元测试的v2.6.3和带有新测试的新3.12.0。但这不是我所问问题的解决方案。