Identify ready2run image #38440
-
Hi! Is there a way of identifying that my app is running using a ready2run compiled version of the code ? |
Beta Was this translation helpful? Give feedback.
Replies: 5 comments 5 replies
-
Beta Was this translation helpful? Give feedback.
-
Open the file using System.Reflection.Metadata and check that |
Beta Was this translation helpful? Give feedback.
-
Ok @davidwrighton , I take it that you comment says that even though the exe-file has non-empty PEReader.PEHeaders.CorHeader.ManagedNativeHeaderDirectory there are more things that determine if the native image is used or not and there is no deterministic api. |
Beta Was this translation helpful? Give feedback.
-
For loaded methods, there is information the assembly and method load events that you can examine to determine:
You can even do this in process. Here's a partial sample that could be fleshed out to capture all of the above. |
Beta Was this translation helpful? Give feedback.
-
Yes, you can determine if your app is using a ReadyToRun (R2R) compiled image by analyzing the PE (Portable Executable) headers. You can do this using the Here’s a quick code snippet for how to inspect it: using System.IO;
using System.Reflection.PortableExecutable;
using System.Reflection.Metadata;
using var stream = File.OpenRead("YourAssembly.dll");
using var reader = new PEReader(stream);
var headers = reader.PEHeaders;
if (headers.CorHeader.ManagedNativeHeaderDirectory.Size > 0)
{
Console.WriteLine("This assembly is ReadyToRun compiled.");
}
else
{
Console.WriteLine("This assembly is not ReadyToRun compiled.");
} |
Beta Was this translation helpful? Give feedback.
Open the file using System.Reflection.Metadata and check that
PEReader.PEHeaders.CorHeader.ManagedNativeHeaderDirectory
is non-empty.