@@ -47,7 +47,7 @@ public void MethodsToSkip_Get_ReturnsZero()
47
47
public void Ctor_Default ( )
48
48
{
49
49
var stackTrace = new StackTrace ( ) ;
50
- VerifyFrames ( stackTrace , false ) ;
50
+ VerifyFrames ( stackTrace , false , 0 ) ;
51
51
}
52
52
53
53
[ Theory ]
@@ -57,7 +57,7 @@ public void Ctor_Default()
57
57
public void Ctor_FNeedFileInfo ( bool fNeedFileInfo )
58
58
{
59
59
var stackTrace = new StackTrace ( fNeedFileInfo ) ;
60
- VerifyFrames ( stackTrace , fNeedFileInfo ) ;
60
+ VerifyFrames ( stackTrace , fNeedFileInfo , 0 ) ;
61
61
}
62
62
63
63
[ Theory ]
@@ -73,7 +73,7 @@ public void Ctor_SkipFrames(int skipFrames)
73
73
Assert . Equal ( emptyStackTrace . FrameCount - skipFrames , stackTrace . FrameCount ) ;
74
74
Assert . Equal ( expectedMethods , stackTrace . GetFrames ( ) . Select ( f => f . GetMethod ( ) ) ) ;
75
75
76
- VerifyFrames ( stackTrace , false ) ;
76
+ VerifyFrames ( stackTrace , false , skipFrames ) ;
77
77
}
78
78
79
79
[ Fact ]
@@ -99,7 +99,7 @@ public void Ctor_SkipFrames_FNeedFileInfo(int skipFrames, bool fNeedFileInfo)
99
99
Assert . Equal ( emptyStackTrace . FrameCount - skipFrames , stackTrace . FrameCount ) ;
100
100
Assert . Equal ( expectedMethods , stackTrace . GetFrames ( ) . Select ( f => f . GetMethod ( ) ) ) ;
101
101
102
- VerifyFrames ( stackTrace , fNeedFileInfo ) ;
102
+ VerifyFrames ( stackTrace , fNeedFileInfo , skipFrames ) ;
103
103
}
104
104
105
105
[ Theory ]
@@ -117,7 +117,7 @@ public void Ctor_LargeSkipFramesFNeedFileInfo_GetFramesReturnsEmpty(bool fNeedFi
117
117
public void Ctor_ThrownException_GetFramesReturnsExpected ( )
118
118
{
119
119
var stackTrace = new StackTrace ( InvokeException ( ) ) ;
120
- VerifyFrames ( stackTrace , false ) ;
120
+ VerifyFrames ( stackTrace , false , 0 ) ;
121
121
}
122
122
123
123
[ Fact ]
@@ -137,7 +137,7 @@ public void Ctor_EmptyException_GetFramesReturnsEmpty()
137
137
public void Ctor_Bool_ThrownException_GetFramesReturnsExpected ( bool fNeedFileInfo )
138
138
{
139
139
var stackTrace = new StackTrace ( InvokeException ( ) , fNeedFileInfo ) ;
140
- VerifyFrames ( stackTrace , fNeedFileInfo ) ;
140
+ VerifyFrames ( stackTrace , fNeedFileInfo , 0 ) ;
141
141
}
142
142
143
143
[ Theory ]
@@ -171,7 +171,7 @@ public void Ctor_Exception_SkipFrames(int skipFrames)
171
171
Assert . Equal ( expectedMethods , frames . Select ( f => f . GetMethod ( ) ) ) ;
172
172
if ( frames != null )
173
173
{
174
- VerifyFrames ( stackTrace , false ) ;
174
+ VerifyFrames ( stackTrace , false , skipFrames ) ;
175
175
}
176
176
}
177
177
@@ -211,7 +211,7 @@ public void Ctor_Exception_SkipFrames_FNeedFileInfo(int skipFrames, bool fNeedFi
211
211
Assert . Equal ( expectedMethods , frames . Select ( f => f . GetMethod ( ) ) ) ;
212
212
if ( frames != null )
213
213
{
214
- VerifyFrames ( stackTrace , fNeedFileInfo ) ;
214
+ VerifyFrames ( stackTrace , fNeedFileInfo , skipFrames ) ;
215
215
}
216
216
}
217
217
@@ -450,7 +450,7 @@ private class ClassWithConstructor
450
450
public ClassWithConstructor ( ) => StackTrace = new StackTrace ( ) ;
451
451
}
452
452
453
- private static void VerifyFrames ( StackTrace stackTrace , bool hasFileInfo )
453
+ private static void VerifyFrames ( StackTrace stackTrace , bool hasFileInfo , int skippedFrames )
454
454
{
455
455
Assert . True ( stackTrace . FrameCount > 0 ) ;
456
456
@@ -467,7 +467,11 @@ private static void VerifyFrames(StackTrace stackTrace, bool hasFileInfo)
467
467
Assert . Equal ( 0 , stackFrame . GetFileLineNumber ( ) ) ;
468
468
Assert . Equal ( 0 , stackFrame . GetFileColumnNumber ( ) ) ;
469
469
}
470
- Assert . NotNull ( stackFrame . GetMethod ( ) ) ;
470
+
471
+ // On native AOT, the reflection invoke infrastructure uses compiler-generated code
472
+ // that doesn't have a reflection method associated. Limit the checks.
473
+ if ( ! PlatformDetection . IsNativeAot || ( i + skippedFrames ) == 0 )
474
+ Assert . NotNull ( stackFrame . GetMethod ( ) ) ;
471
475
}
472
476
}
473
477
}
0 commit comments