What is the purpose of the "Prefer 32-bit" setting in Visual Studio and how does it actually work?
Solution 1:
Microsoft has a blog entry What AnyCPU Really Means As Of .NET 4.5 and Visual Studio 11:
In .NET 4.5 and Visual Studio 11 the cheese has been moved. The default for most .NET projects is again AnyCPU, but there is more than one meaning to AnyCPU now. There is an additional sub-type of AnyCPU, “Any CPU 32-bit preferred”, which is the new default (overall, there are now five options for the /platform C# compiler switch: x86, Itanium, x64, anycpu, and anycpu32bitpreferred). When using the "Prefer 32-Bit" flavor of AnyCPU, the semantics are as follows:
- If the process runs on a 32-bit Windows system, it runs as a 32-bit process. IL is compiled to x86 machine code.
- If the process runs on a 64-bit Windows system, it runs as a 32-bit process. IL is compiled to x86 machine code.
- If the process runs on an ARM Windows system, it runs as a 32-bit process. IL is compiled to ARM machine code.
The difference, then, between “Any CPU 32-bit preferred” and “x86” is only this: a .NET application compiled to x86 will fail to run on an ARM Windows system, but an “Any CPU 32-bit preferred” application will run successfully.
Solution 2:
Here's a simple answer:
Note: AnyCPU-32bitPreferred is only available in .Net version 4.5 and higher.