#ifndef DACCESS_COMPILE
#ifdef FEATURE_NATIVE_IMAGE_GENERATION
- // Check we're NGEN'ing
- if (IsCompilationProcess())
+ // Check we're NGEN'ing. ComputeLoaderModuleForCompilation algorithm assumes that there is fragile
+ // NGen image for CoreLib that is not the case for ReadyToRun compilation.
+ if (IsCompilationProcess() && !IsReadyToRunCompilation())
{
RETURN(ComputeLoaderModuleForCompilation(pDefinitionModule, token, classInst, methodInst));
}
if (actualMachineType == IMAGE_FILE_MACHINE_I386 && ((peKind & (peILonly | pe32BitRequired)) == peILonly))
return; // Image is marked CPU-agnostic.
- if (actualMachineType != IMAGE_FILE_MACHINE_NATIVE)
+ if (actualMachineType != IMAGE_FILE_MACHINE_NATIVE && actualMachineType != IMAGE_FILE_MACHINE_NATIVE_NI)
{
#ifdef _TARGET_AMD64_
// v4.0 64-bit compatibility workaround. The 64-bit v4.0 CLR's Reflection.Load(byte[]) api does not detect cpu-matches. We should consider fixing that in
{
LIMITED_METHOD_CONTRACT;
+ // Never use fragile native image content during ReadyToRun compilation. It would
+ // produces non-version resilient images because of wrong cached values for
+ // MethodTable::IsLayoutFixedInCurrentVersionBubble, etc.
+ if (IsReadyToRunCompilation())
+ return TRUE;
+
// Ask profiling API & config vars whether NGENd images should be avoided
// completely.
if (!NGENImagesAllowed())