@@ -32,6 +32,12 @@ internal InvocationFlags ComputeAndUpdateInvocationFlags()
3232 {
3333 invocationFlags = InvocationFlags . NoInvoke ;
3434 }
35+ // This check assumes that all MethodImplAttributes.Async methods on AsyncHelpers are the only non-task returning async methods
36+ // with special calling convention
37+ else if ( declaringType == typeof ( AsyncHelpers ) && ( GetMethodImplementationFlags ( ) & MethodImplAttributes . Async ) != 0 )
38+ {
39+ invocationFlags = InvocationFlags . NoInvoke ;
40+ }
3541 else if ( declaringType . IsByRefLike ) // Check for byref-like types
3642 {
3743 invocationFlags |= InvocationFlags . ContainsStackPointers ;
@@ -60,6 +66,8 @@ static bool IsDisallowedByRefType(Type type)
6066 [ DoesNotReturn ]
6167 internal void ThrowNoInvokeException ( )
6268 {
69+ Type ? declaringType = DeclaringType ;
70+
6371 // method is on a class that contains stack pointers
6472 if ( ( InvocationFlags & InvocationFlags . ContainsStackPointers ) != 0 )
6573 {
@@ -71,7 +79,7 @@ internal void ThrowNoInvokeException()
7179 throw new NotSupportedException ( ) ;
7280 }
7381 // method is generic or on a generic class
74- else if ( DeclaringType ! . ContainsGenericParameters || ContainsGenericParameters )
82+ else if ( ( declaringType != null && declaringType . ContainsGenericParameters ) || ContainsGenericParameters )
7583 {
7684 throw new InvalidOperationException ( SR . Arg_UnboundGenParam ) ;
7785 }
@@ -88,6 +96,10 @@ internal void ThrowNoInvokeException()
8896 if ( elementType == typeof ( void ) )
8997 throw new NotSupportedException ( SR . NotSupported_ByRefToVoidReturn ) ;
9098 }
99+ else if ( declaringType == typeof ( AsyncHelpers ) && ( GetMethodImplementationFlags ( ) & MethodImplAttributes . Async ) != 0 )
100+ {
101+ throw new NotSupportedException ( SR . NotSupported_Async ) ;
102+ }
91103
92104 throw new TargetException ( ) ;
93105 }
0 commit comments