@@ -7233,8 +7233,17 @@ mono_method_to_ir (MonoCompile *cfg, MonoMethod *method, MonoBasicBlock *start_b
7233
7233
} else if ((cmethod -> iflags & METHOD_IMPL_ATTRIBUTE_INTERNAL_CALL ) && direct_icalls_enabled (cfg , cmethod )) {
7234
7234
direct_icall = TRUE;
7235
7235
} else if (fsig -> pinvoke ) {
7236
- MonoMethod * wrapper = mono_marshal_get_native_wrapper (cmethod , TRUE, cfg -> compile_aot );
7237
- fsig = mono_method_signature_internal (wrapper );
7236
+ if (cmethod -> flags & METHOD_ATTRIBUTE_PINVOKE_IMPL ) {
7237
+ /*
7238
+ * Avoid calling mono_marshal_get_native_wrapper () too early, it might call managed
7239
+ * callbacks on netcore.
7240
+ */
7241
+ fsig = mono_metadata_signature_dup_mempool (cfg -> mempool , fsig );
7242
+ fsig -> pinvoke = FALSE;
7243
+ } else {
7244
+ MonoMethod * wrapper = mono_marshal_get_native_wrapper (cmethod , TRUE, cfg -> compile_aot );
7245
+ fsig = mono_method_signature_internal (wrapper );
7246
+ }
7238
7247
} else if (constrained_class ) {
7239
7248
} else {
7240
7249
fsig = mono_method_get_signature_checked (cmethod , image , token , generic_context , cfg -> error );
@@ -7397,8 +7406,7 @@ mono_method_to_ir (MonoCompile *cfg, MonoMethod *method, MonoBasicBlock *start_b
7397
7406
int costs ;
7398
7407
gboolean always = FALSE;
7399
7408
7400
- if ((cmethod -> iflags & METHOD_IMPL_ATTRIBUTE_INTERNAL_CALL ) ||
7401
- (cmethod -> flags & METHOD_ATTRIBUTE_PINVOKE_IMPL )) {
7409
+ if (cmethod -> iflags & METHOD_IMPL_ATTRIBUTE_INTERNAL_CALL ) {
7402
7410
/* Prevent inlining of methods that call wrappers */
7403
7411
INLINE_FAILURE ("wrapper call" );
7404
7412
// FIXME? Does this write to cmethod impact tailcall_supported? Probably not.
0 commit comments