Skip to content

Commit 11c9394

Browse files
authored
Fix for bug #53520, Entry point not found (#53772)
Manish investigated this issue and he found out that the problem is caused by the fact that in the method Newtonsoft.Json.Utilities.ReflectionUtils.GetFields Crossgen2 produces a NewObject fixup for the incorrect type System.Collections.Generic.List`1<System.Type> instead of the right type System.Collections.Generic.List`1<System.Reflection.MemberInfo> This was caused by a bug in the token harvesting logic; at some point resolveToken was asked to resolve the token 0x0A02BA, string [System.Runtime/*23000001*/]System.Type/*01000019*/::get_Name() /* 0A0002BA */ As part of the token harvesting logic we looked at the MethodReference.Parent (01000019) and stored it in the harvesting table along with the OwningType of the method. The problem is that the translation of the MemberReference to MethodDesc resolves the method on a base class, string [System.Reflection/*23000009*/]System.Reflection.MemberInfo/*01000076*/::get_Name() /* 0A0002B5 */ As a result we were storing the incorrect [token - type] pair [01000019 - System.Reflection.MemberInfo] into the type token translation table and that confused the signature encoder because 01000019 is System.Type. The trivial solution is to separately translate the memberref parent entity handle to the owning type entity instead than extracting it from the MethodDesc. I have verified using R2RDump that I now see the correct NewObject fixup getting generated in the method. Thanks Tomas
1 parent 2e7e66d commit 11c9394

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

src/coreclr/tools/aot/ILCompiler.ReadyToRun/Compiler/DependencyAnalysis/ReadyToRun/ModuleTokenResolver.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,8 @@ public void AddModuleTokenForMethod(MethodDesc method, ModuleToken token)
139139
{
140140
MemberReference memberRef = token.MetadataReader.GetMemberReference((MemberReferenceHandle)token.Handle);
141141
EntityHandle owningTypeHandle = memberRef.Parent;
142-
AddModuleTokenForType(method.OwningType, new ModuleToken(token.Module, owningTypeHandle));
142+
TypeDesc owningType = (TypeDesc)token.Module.GetObject(owningTypeHandle, NotFoundBehavior.Throw);
143+
AddModuleTokenForType(owningType, new ModuleToken(token.Module, owningTypeHandle));
143144
memberRef.DecodeMethodSignature<DummyTypeInfo, ModuleTokenResolver>(new TokenResolverProvider(this, token.Module), this);
144145
}
145146
}

0 commit comments

Comments
 (0)