@@ -176,10 +176,27 @@ public void StackTraceHelper_ProducesReadableOutput()
176176
177177 // Act
178178 var stackFrames = StackTraceHelper . GetFrames ( exception , out _ ) ;
179- var methodNames = stackFrames . Select ( stackFrame => stackFrame . MethodDisplayInfo . ToString ( ) ) . ToArray ( ) ;
180-
181- // Assert
182- Assert . Equal ( expectedCallStack , methodNames ) ;
179+ var methodNames = stackFrames . Select ( stackFrame => stackFrame . MethodDisplayInfo . ToString ( ) ) . ToList ( ) ;
180+
181+ // Assert - Runtime-agnostic checks for essential stack trace components
182+ // Instead of exact string matching, verify key components are present
183+ Assert . Equal ( expectedCallStack . Count , methodNames . Count ) ;
184+
185+ // Check each frame contains the essential method information
186+ Assert . Contains ( "Iterator()+MoveNext()" , methodNames [ 0 ] ) ;
187+ Assert . Contains ( "string.Join" , methodNames [ 1 ] ) ;
188+ Assert . Contains ( "GenericClass<T>.GenericMethod<V>" , methodNames [ 2 ] ) ;
189+ Assert . Contains ( "MethodAsync(int value)" , methodNames [ 3 ] ) ;
190+
191+ // For async generic method, check for either resolved form or state machine form
192+ var asyncGenericFrame = methodNames [ 4 ] ;
193+ Assert . True (
194+ asyncGenericFrame . Contains ( "MethodAsync<TValue>(TValue value)" ) || // CoreCLR resolved form
195+ asyncGenericFrame . Contains ( "MethodAsync" ) && asyncGenericFrame . Contains ( "TValue" ) , // Mono state machine form
196+ $ "Expected async generic method info in: { asyncGenericFrame } ") ;
197+
198+ Assert . Contains ( "Method(string value)" , methodNames [ 5 ] ) ;
199+ Assert . Contains ( "StackTraceHelper_ProducesReadableOutput()" , methodNames [ 6 ] ) ;
183200 }
184201
185202 [ Fact ]
@@ -242,9 +259,12 @@ public void GetFrames_DoesNotFailForDynamicallyGeneratedAssemblies()
242259 // Assert
243260 var frame = frames [ 0 ] ;
244261 Assert . Null ( frame . FilePath ) ;
245- // lambda_method{RandomNumber}(Closure )
246- Assert . StartsWith ( "lambda_method" , frame . MethodDisplayInfo . ToString ( ) ) ;
247- Assert . EndsWith ( "(Closure )" , frame . MethodDisplayInfo . ToString ( ) ) ;
262+ // Runtime-agnostic test: should contain "lambda_method" regardless of prefix
263+ // CoreCLR: "lambda_method34(Closure )"
264+ // Mono: "object.lambda_method34(Closure )"
265+ var methodDisplay = frame . MethodDisplayInfo . ToString ( ) ;
266+ Assert . Contains ( "lambda_method" , methodDisplay ) ;
267+ Assert . EndsWith ( "(Closure )" , methodDisplay ) ;
248268 }
249269
250270 [ MethodImpl ( MethodImplOptions . NoOptimization | MethodImplOptions . NoInlining ) ]
0 commit comments