On a 32-bit machine:
- Any CPU: runs as a 32-bit process, can load Any CPU and x86 assemblies, will get
BadImageFormatException
if it tries to load an x64 assembly. - x86: same as Any CPU.
- x64:
BadImageFormatException
always.
On a 64-bit machine:
- Any CPU: runs as a 64-bit process, can load Any CPU and x64 assemblies, will get
BadImageFormatException
if it tries to load an x86 assembly. - x86: runs as a 32-bit process, can load Any CPU and x86 assemblies, will get
BadImageFormatException
if it tries to load an x64 assembly. - x64: same as Any CPU.
Also CorFlags.exe assembly.dll|assembly.exe will tell us whether it is targeted x86 or Any CPU
Just for clarification, CorFlags.exe is part of the .NET Framework SDK. I have the development tools on my machine, and the simplest way for me determine whether a DLL is 32-bit only is to:
- Open the Visual Studio Command Prompt (In Windows: menu Start/Programs/Microsoft Visual Studio/Visual Studio Tools/Visual Studio 2008 Command Prompt)
- CD to the directory containing the DLL in question
- Run corflags like this: corflags MyAssembly.dll
Microsoft (R) .NET Framework CorFlags Conversion Tool. Version 3.5.21022.8
Copyright (c) Microsoft Corporation. All rights reserved.
Version : v2.0.50727
CLR Header: 2.5
PE : PE32CorFlags : 3
ILONLY : 1
32BIT : 1
Signed : 0
The key is the "32BIT" flag as documented above: 1 = x86; 0 = Any CPU.
· Any CPU: PE = PE32 and 32BIT = 0
· x86: PE = PE32 and 32BIT = 1
· x64: PE = PE32+ and 32BIT = 0