diff --git a/src/coreclr/tools/aot/ILCompiler.ReadyToRun/Compiler/ReadyToRunCompilationModuleGroupBase.cs b/src/coreclr/tools/aot/ILCompiler.ReadyToRun/Compiler/ReadyToRunCompilationModuleGroupBase.cs index 09c12867e50b16..a2ea17ccc111b8 100644 --- a/src/coreclr/tools/aot/ILCompiler.ReadyToRun/Compiler/ReadyToRunCompilationModuleGroupBase.cs +++ b/src/coreclr/tools/aot/ILCompiler.ReadyToRun/Compiler/ReadyToRunCompilationModuleGroupBase.cs @@ -707,6 +707,11 @@ private bool IsNonVersionableWithILTokensThatDoNotNeedTranslationUncached(EcmaMe public sealed override bool GeneratesPInvoke(MethodDesc method) { + // Marshalling behavior isn't modeled as protected by R2R rules, so prevent inlining of marshalling + // defined outside of the version bubble. + if (!VersionsWithMethodBody(method)) + return false; + return !Marshaller.IsMarshallingRequired(method); } diff --git a/src/coreclr/tools/aot/ILCompiler.ReadyToRun/JitInterface/CorInfoImpl.ReadyToRun.cs b/src/coreclr/tools/aot/ILCompiler.ReadyToRun/JitInterface/CorInfoImpl.ReadyToRun.cs index 4ec4ff34e6e1a7..c39971017ce7ec 100644 --- a/src/coreclr/tools/aot/ILCompiler.ReadyToRun/JitInterface/CorInfoImpl.ReadyToRun.cs +++ b/src/coreclr/tools/aot/ILCompiler.ReadyToRun/JitInterface/CorInfoImpl.ReadyToRun.cs @@ -3085,11 +3085,6 @@ private bool pInvokeMarshalingRequired(CORINFO_METHOD_STRUCT_* handle, CORINFO_S Debug.Assert(!_compilation.NodeFactory.CompilationModuleGroup.GeneratesPInvoke(method)); return true; } - - // Marshalling behavior isn't modeled as protected by R2R rules, so disable pinvoke inlining for code outside - // of the version bubble - if (!_compilation.CompilationModuleGroup.VersionsWithMethodBody(method)) - return true; } catch (RequiresRuntimeJitException) {