Wrong interpretation of public key token of core library
See original GitHub issueInitial code used PublicKeyToken to determine if a referenced assembly is actually the core library (e.g. “mscorlib”). This wrong approach is made its way to till to date. PublicKeyToken is actually hash of public key and it’s what used during signing. So, PublicKeyToken is actually same for assemblies which Microsoft used same private key.
We should use fully qualified assembly name instead of PublicKeyToken. But, there is another problem that should be fixed as well. For example, System.Random resides in System.Runtime.Extensions assembly. If we try to get the assembly with:
var asm = typeof(System.Random).Assembly.GetName();
Console.WriteLine(asm.FullName);
// On .NET Core, prints:
// System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e
So, mapping System.Private.CoreLib to System.Runtime will lead a crash. Because, System.Runtime does not have any reference for System.Random.
So, correct core library mapping is actually somewhat more complex. One of the possible way is to build a type dictionary for known assemblies like:
var knownAssemblyNames = new []{ "System.Runtime", "System.Runtime.Extensions", /* ... */ };
foreach (var name in knownAssemblyNames) {
var asm = Assembly.Load(name);
var types = asm.GetTypes();
AddKnownTypeReference(name, types);
}
Issue Analytics
- State:
- Created 5 years ago
- Comments:7 (4 by maintainers)

Top Related StackOverflow Question
@vermorel This one can be closed - the related PR #161 has already merged.
Hi, PR #61 has since been merged last year, and I’m now getting an issue where
System.Private.CoreLibisn’t being mapped toSystem.Runtimein .NET Core 3.0 and 3.1 (haven’t tested earlier versions) builds and runtimes, in both a console app and in an NUnit test.produces the following assembly: TestAssemblyA.zip
Note that this assembly has a reference to
System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798erather thanSystem.Runtime, Version=4.2.2.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a