Bug? GetPEKind varies between .NET 8.0 and .NET 9.x - why? #113727
Replies: 4 comments 2 replies
-
I took a look at the code for .NET 8.0.0 and 9.0.0, and the code is all the same. It looks like it's reading the image type right out of the file. |
Beta Was this translation helpful? Give feedback.
-
I notice the code will return I386 if the READYTORUN_FLAG_PLATFORM_NEUTRAL_SOURCE (0x1) bit of the core flag is set. For some reason the core flag for System.Private.CoreLib.dll in 9.0 is 4B, while in 8.0 it is 4A. However, most DLLs in version 8.0 set this bit. |
Beta Was this translation helpful? Give feedback.
-
@geniuszxy Does this sound like a bug? Should I create an issue from this? |
Beta Was this translation helpful? Give feedback.
-
In .NET 8, corelib was compiled as architecture-specific on some platforms and platform neutral on others. All other core libraries were compiled as platform neutral. In .NET 9, all core libraries including corelib are compiled as platform neutral everywhere. This change is related to dotnet/sdk#42556. using System.Reflection;
Assembly.GetAssembly(typeof(int)).GetModules()[0].GetPEKind(out var peKind, out var machine);
Console.WriteLine($"{peKind} {machine}");
Assembly.GetAssembly(typeof(System.Diagnostics.Process)).GetModules()[0].GetPEKind(out var peKind2, out var machine2);
Console.WriteLine($"{peKind2} {machine2}"); Output on .NET 8:
Output on .NET 9:
|
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
We are using an SAP-provided DLL that detects "bitness" by using the following call:
On upgrading from .NET 8.0 to .NET 9.0, the DLL no longer functions because the return value has changed.
Using this as my CSPROJ:
and this code:
You'll see that the output varies from one version to another.
Even if I explicitly set .NET 9.0 to be
<PlatformTarget>x64</PlatformTarget>
, it still returnsI386
instead ofAMD64
.Why?
Beta Was this translation helpful? Give feedback.
All reactions