.NET Software running on x64 but compiled on x86 for Any CPU (VS2008)

510 views Asked by At

I have a problem, whereby I’m getting runtime errors with a compiled program. This works fine in the development environment (x86), but not on the production environment (which is x64).

I found this article, which seems to imply that compiling the software as Any CPU may run the software as x64 software if it’s run in a 64 bit environment.

Is this the case, and if so, should software ever be compiled under Any CPU (as it seems to make for a mismatch between the two environments)?

1

There are 1 answers

0
Helge Klein On BEST ANSWER

AnyCPU is great if you are using managed code only. Managed code can be executed in a 32-bit-process or 64-bit-process. With AnyCPU, the framework chooses the bitness native to the OS.

The same is not true for unmanaged code. It needs to be compiled either as 32-bit or 64-bit code. Of course, due to the WoW64 subsystem, 64-bit Windows can run 64-bit processes.

But 64-bit processes cannot load 32-bit modules (DLLs, OCXs, etc.).

That means if your program is using unmanaged modules of some kind, better make sure to set the bitness manually so that all components have the same bitness.