views:

113

answers:

2

What version of .NET (64-bit vs. 32-bit) will be loaded if some of the assemblies referenced in an app are compiled with 32-bit only (instead of AnyMachine) setting? Will the app still run as 64-bit or will it be forced to run as 32-bit if at least one of the referenced assemblies is compiled as 32-bit only? The app is running .NET 3.5.

+4  A: 

The application will be forced to run as 32-bit

Gregory Pakosz
And if the assembly is dynamically loaded, and the process is 64bit, the 32bit assembly will fail to load.
EricLaw -MSFT-
And if the referenced assembly is compiled as AnyCPU but making use of an unmanaged DLL, then it will fail to run if you don't provide a 64bit version of the unmanaged DLL
Gregory Pakosz
Isn't the bit-ness of the process determined by the main executable, and if that module references assemblies of a different bit-ness, those will fail to load, not force the process to a different bit-ness? For instance, if you create a executable and compile it for AnyCPU, but it references a bunch of 32-bit assemblies, the process will run fine on a 32-bit OS, but fail to load the additional assemblies on a 64-bit OS?
Lasse V. Karlsen
+2  A: 

The bit-ness is determined by the Platform Target setting on the EXE. There is no mechanism to ensure that a EXE that references a 32-bit only assembly will be forced to run in 32-bit mode as well. The assembly will simply fail to load with a BadImageFormatException.

If your program has a dependency on such a DLL then you must force the Platform Target on your EXE project from AnyCPU to x86.

Hans Passant
Would it fail at the very beginning of the app or when the assembly is acually used?
When it is used. Which could be close to the beginning.
Hans Passant