diff --git a/src/coreclr/nativeaot/System.Private.CoreLib/src/System/Threading/Thread.NativeAot.cs b/src/coreclr/nativeaot/System.Private.CoreLib/src/System/Threading/Thread.NativeAot.cs index ba2550eb364aba..2564eec546c229 100644 --- a/src/coreclr/nativeaot/System.Private.CoreLib/src/System/Threading/Thread.NativeAot.cs +++ b/src/coreclr/nativeaot/System.Private.CoreLib/src/System/Threading/Thread.NativeAot.cs @@ -369,7 +369,7 @@ private void StartCore() if (GetThreadStateBit(ThreadState.Unstarted)) { Exception? startException = _startException; - startException = null; + _startException = null; throw new ThreadStartException(startException ?? new OutOfMemoryException()); } diff --git a/src/libraries/System.Threading.Thread/tests/ThreadTests.cs b/src/libraries/System.Threading.Thread/tests/ThreadTests.cs index cf6c5e0c31f6a4..09dc1d0b5ce342 100644 --- a/src/libraries/System.Threading.Thread/tests/ThreadTests.cs +++ b/src/libraries/System.Threading.Thread/tests/ThreadTests.cs @@ -291,7 +291,8 @@ public static void ApartmentStateTest_ChangeBeforeThreadStarted_Windows_Nano_Ser Assert.Equal(setType == 0 ? 0 : 2, setApartmentState(t, ApartmentState.MTA)); // cannot be changed more than once Assert.Equal(ApartmentState.STA, getApartmentState(t)); - Assert.Throws(() => t.Start()); // Windows Nano Server does not support starting threads in the STA. + Exception ex = Assert.Throws(() => t.Start()); // Windows Nano Server does not support starting threads in the STA. + Assert.IsType(ex.InnerException); }