How do I get the PEKind and ImageFileMachine of an AMD64 assembly from an x86.NET application (and vice versa)?

I am writing an installation checker tool for our product and I need to get some PE information from multiple installed builds. Regardless of which platform our product is installed on, we ship AMD64, x86 and MSIL assemblies to specific locations to allow users to create deployment projects for those platforms.

The problem is that using the following code:

Module manifestModule = Assembly.LoadFile(fileName).ManifestModule;
ImageFileMachine m;
PortableExecutableKinds pe;
manifestModule.GetPEKind(out pe, out m);

      

Assembly.LoadFile (...) will break if the application runs as x86 and tries to load an AMD64 assembly or vice versa.

I found these related, but not quite:

0


a source to share


1 answer


Try using Assembly.ReflectionOnlyLoad. This will allow you to load the assembly into memory, but will not execute any code. which will allow loading x64 assemblies to be reflected in the x86 process.



0


a source







All Articles