2424// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
2525// ***********************************************************************
2626
27- #if __IOS__ || __WATCHOS__ || __TVOS__
28- #define NO_REMOTING
29- #endif
30-
3127using System ;
3228using System . Diagnostics ;
3329using System . Threading ;
@@ -76,14 +72,12 @@ public class FinallyDelegate
7672 // Thread_1 creates Thread_2, it needs to have the same "thread local" values.
7773 // that is achieved with `CallContext`.
7874 //
79- // Unfortunately, remoting isn't available on every platform, thus we can't
80- // support this scenario. Luckily, this scenario is very rare.
75+ // Unfortunately, remoting isn't available on every platform (it will
76+ // throw PlatformNotSupportedexception), thus we can't support this
77+ // scenario. Luckily, this scenario is very rare.
8178
82- #if NO_REMOTING
83- static Container container ;
84- #else
79+ Container container = null ;
8580 private static readonly string CONTEXT_KEY = "TestResultName" ;
86- #endif
8781
8882 public FinallyDelegate ( ) {
8983 this . testStack = new Stack < Tuple < TestExecutionContext , long , TestResult > > ( ) ;
@@ -96,22 +90,18 @@ public void Set (TestExecutionContext context, long startTicks, TestResult resul
9690 /* keep name in LogicalCallContext, because this will be inherited by
9791 * Threads spawned by the test case */
9892 var guid = Guid . NewGuid ( ) ;
99- #if NO_REMOTING
100- container = new Container ( guid ) ;
101- #else
102- CallContext . SetData ( CONTEXT_KEY , new Container ( guid ) ) ;
103- #endif
93+ try {
94+ CallContext . SetData ( CONTEXT_KEY , new Container ( guid ) ) ;
95+ } catch {
96+ container = new Container ( guid ) ;
97+ }
10498
10599 this . lookupTable . Add ( guid , result ) ;
106100 this . testStack . Push ( frame ) ;
107101 }
108102
109103 public void HandleUnhandledExc ( Exception ex ) {
110- #if NO_REMOTING
111- Container c = container ;
112- #else
113- Container c = ( Container ) CallContext . GetData ( CONTEXT_KEY ) ;
114- #endif
104+ Container c = container ?? ( Container ) CallContext . GetData ( CONTEXT_KEY ) ;
115105 TestResult result = this . lookupTable [ c . guid ] ;
116106 result . RecordException ( ex ) ;
117107 result . ThreadCrashFail = true ;
0 commit comments