Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why is the default platform target for a WPF applications in Visual Studio x86 and not AnyCPU?

When I create a new WPF application in Visual Studio 2012 the platform target and build configuration is set to x86 by default. Why is this the case? For a plain WPF application (without any references to mixed mode assemblies) is there any danger using AnyCPU so my WPF executable will be JITed to x64 code on my x64 machine and to x86 on a x86 machine?

like image 821
bitbonk Avatar asked Jun 14 '12 16:06

bitbonk


People also ask

What is AnyCPU in Visual Studio?

The default setting, "Any CPU", means that the assembly will run natively on the CPU it is currently running on. Meaning, it will run as 64-bit on a 64-bit machine and 32-bit on a 32-bit machine. If the assembly is called from a 64-bit application, it will perform as a 64-bit assembly and so on.

How do I change from x86 to x64 in Visual Studio?

From the BUILD menu in Visual Studio, select Configuration Manager. From the Active solution platform drop-down list, select New. The New Solution Platform dialog displays. In the Type or select new platform combination box, select x64.


2 Answers

Why is this the case?

For most applications, building as 32bit is actually better. 64bit provides few benefits, and some significant disadvantages in most cases (much higher memory usage, more complex dependency management with multiple platforms, worse debugging experience, etc).

If, however, your application needs to be able to use large amounts of memory, then of course 64bit has advantages (and is easy to switch in VS), but most applications do not fall into this boat.

This is why the new default in VS 2012 is to use AnyCPUPrefer32Bit instead of AnyCPU for applications.

like image 137
Reed Copsey Avatar answered Nov 18 '22 02:11

Reed Copsey


According to this bug report, it was done because of problems with Edit and Continue on x64 machines with x64 code. By changing it to x86, Edit and Continue works properly.

There should be no danger in switching it to AnyCPU. I always do this.

like image 36
Joel Rondeau Avatar answered Nov 18 '22 00:11

Joel Rondeau