You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Apartment(ApartmentState.STA) doesn't works together with Timeout
I'm currently updating projects from .NET Framework (NUnit 3.10.1) to .NET 6 (NUnit 3.13.3) and found this problem. Real tests do some WPF relates stuff, so it requires STA apartment. The Timeout is used to prevent the test from running indefinitely when something goes wrong.
NUnit Console 3.15.0 (Release)
Copyright (c) 2022 Charlie Poole, Rob Prouse
30 мая 2022 г. 21:21:19
Runtime Environment
OS Version: Microsoft Windows 10.0.18362
Runtime: .NET 6.0.4
Test Files
.\TestProject1.dll
SomeTestWithoutTimeout 6 STA
SomeTestWithTimeout 8 MTA
The text was updated successfully, but these errors were encountered:
Timeout targeting anything other than .NETFramework is not safe (see #4021) and we have not found a solution for this.
The library has to create a new thread to run the test in and hope for the best as it cannot stop it (MS dropped Thread.Abort). This doesn't work with STA components created in a SetUp method. I suggest to refactor your test that they don't need Timeout at all.
The library has to create a new thread to run the test in and hope for the best as it cannot stop it
But why does it create a thread without a specified Apartment?
In my opinion, if Timeout can't really work on newer .NETs, it shouldn't break other things like Apartment.
Updated docs about this limitation and some runtime or compile-time checks would also be acceptable.
Apartment(ApartmentState.STA) doesn't works together with Timeout
I'm currently updating projects from .NET Framework (NUnit 3.10.1) to .NET 6 (NUnit 3.13.3) and found this problem. Real tests do some WPF relates stuff, so it requires STA apartment. The Timeout is used to prevent the test from running indefinitely when something goes wrong.
An example of minimalistic tests:
nunit3-console output:
The text was updated successfully, but these errors were encountered: