29. July 2011 12:12
When using 3rd party assemblies it is sometimes useful to know if they have been compiled to x86, x64 or AnyCPU. One way to do this is to open ildasm(e.g. from Visual Studio Command Prompt) and open the assembly.
After opening the assembly double click the manifest and scroll to bottom where you’ll see .corflags.
Most of the time we want to find out if the assembly is compiled as x86 or AnyCPU. This is the easiest case. If the assembly is compiled as AnyCPU you’ll see the following.
.corflags 0x00000001 // ILONLY
If the assembly is compiled as x86 you’ll see the following
.corflags 0x00000003 // ILONLY 32BITREQUIRED
Comparing AnyCPU to x64 is not so easy because the .corflags is the same for both. This is when the corflags.execomes in handy. You can execute it in Visual Studio Command Prompt like this.
Version : v4.0.30319
CLR Header: 2.5
PE : PE32
CorFlags : 1
ILONLY : 1
32BIT : 0
Signed : 0
To find out whether assembly is x86, x64 or AnyCPU you have to look at the PE and 32BIT flags. The following table shows the combinations.
As you can see with x64 assemblies PE is PE32+ and 32BIT is zero. Next time you have to find out what the platform target is for any given assembly, use the corflags.exe and refer to the table above.