Home > General > Check whether a .NET dll is built for Any CPU, x86, or x64

Check whether a .NET dll is built for Any CPU, x86, or x64

As much as I would like all builds to come from a build server, many times a build comes from a developer’s machine. When I receive a build from another developer’s machine, I need to check if their build is targeting the correct platform.

I can use CorFlags.exe, which is part of the .NET Framework SDK, to find out this information from a dll. Running CorFlags.exe with the file path to the dll will produce the following output:

>> CorFlags "C:\example.dll"

Microsoft (R) .NET Framework CorFlags Conversion Tool.  Version
Copyright (c) Microsoft Corporation.  All rights reserved.

Version   : v4.0.30319
CLR Header: 2.5
PE        : PE32
CorFlags  : 0x3
ILONLY    : 1
32BITREQ  : 1
Signed    : 0

The two fields we need to look at are “PE” and “32BITREQ”.

Any CPU PE: PE32, 32BITREQ: 0
x86 PE: PE32, 32BITREQ: 1
x64 PE: PE32+, 32BITREQ: 0

To programmatically determine the target platform, we can use Module.GetPEKind().

Assembly a = Assembly.ReflectionOnlyLoadFrom(@"C:\example.dll");

PortableExecutableKinds peKind;
ImageFileMachine machine;

a.ManifestModule.GetPEKind(out peKind, out machine);


The results of peKind can be interpreted with:

Any CPU ILOnly
x86 ILOnly, Required32Bit
x64 ILOnly, PE32Plus
  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: