Skip to content

Commit

Permalink
Fix not to use Thread.CurrentThread in net8.0
Browse files Browse the repository at this point in the history
  • Loading branch information
y-iihoshi committed Dec 9, 2023
1 parent 9153417 commit de6365b
Showing 1 changed file with 5 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,13 @@ public sealed class STATestMethodAttribute : TestMethodAttribute
{
public override TestResult[] Execute(ITestMethod testMethod)
{
#if NET8_0_OR_GREATER
// Although the root cause is unknown, accessing Thread.CurrentThread
// might raise System.NullReferenceException in net8.0.
#else
if (Thread.CurrentThread.GetApartmentState() == ApartmentState.STA)
return base.Execute(testMethod);
#endif

TestResult[]? result = null;
var thread = new Thread(() => result = base.Execute(testMethod));
Expand Down

0 comments on commit de6365b

Please sign in to comment.