15

I have a Any CPU application installed to Program Files (x86). On one Windows 7 x64 machine, it runs as x64 as expected while on another Windows 7 x64 machine, it runs as x86!

How can this be? I expected it to run as x64 on both machines. What might be the reason and what can I do to always make it run as x64?

Does it matter where I am running it from - Program Files (x86) in my case?

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
BobbyHill
  • 151
  • 1
  • 3
  • 1
    Is the program in "Program Files (x86)" on both machines? – Will A Jun 10 '11 at 10:28
  • 1
    @WillA where the program lies isn't important. A 32-bit program can be stored in `\Program Files` while a 64-bit program can be in `\Program Files (x86)`. They will be all loaded correctly because the instruction set info has been written in the header – phuclv May 10 '14 at 02:26

1 Answers1

13

It's likely that you linked some assemblies that are not Any CPU, but include native code (or are compiled as x86), which cause the entire process to fall back to x86.

To understand how your assemblies are compiled, a related Stack Overflow question that might help is How to determine if a .NET assembly was built for x86 or x64?*.

Note: the location of the executable on the file system does not matter at all.

Community
  • 1
  • 1
Dario Solera
  • 5,694
  • 3
  • 29
  • 34
  • 2
    But then, how did it manage to run as x64 on a different machine? – GSerg Jun 10 '11 at 10:29
  • 4
    Wild guess: different versions of the same dependent assembly in the GAC. I ran into this problem with TFS assemblies and I've spent literally *days* to figure out the problem. – Dario Solera Jun 10 '11 at 10:30
  • 1
    @GSerg - for example, if you have referenced drivers (like database drivers), and one user has only got the 32 bit versions installed it will force your app to run as 32 bit as well. – slugster Jun 10 '11 at 10:37
  • 1
    I have just faced a similar problem. In my case, the fix was easy - on the Build tab of the project Properties, the Prefer 32-bit (just below the Platform target, which called Any CPU) was turned on. – Viliam Mar 04 '19 at 15:43
  • Nice one @Viliam. This i was the fix for me. – ossentoo Apr 28 '20 at 10:54
  • Well that's annoying. I had the Active (Debug) configuration selected, and Prefer 32-bit was not checked. I changed the configuration to Debug, and now it's checked? And it stays checked when going back to Active (Debug). Seems like there's a bug with this checkbox sometimes showing it's unchecked when it's not. – Kevin Doyon Dec 17 '20 at 18:35