32-bit Flag in Visual Studio 2013

In Visual Studio 2013 Microsoft introduced a new setting Prefer 32-bit for projects that compile as executables, such as Console applications. This setting causes the compiler to set a flag in the header of the executable instructing it to be run in 32-bit mode if possible. This is switched on by default for new projects.

The following post goes into more detail:
http://stackoverflow.com/questions/12066638/what-is-the-purpose-of-the-prefer-32-bit-setting-in-visual-studio-2012-and-how

It is possible to see if an application is running in 32-bit or 64-bit mode through the Task Manager. On Windows Server 2012 there is a column "Platform" with this information. On Windows Server 2008 the name of the application is appended with "*32".

This seems a strange choice of default value from Microsoft as it is inconsistent with the behaviour in previous versions of Visual Studio which would implicitly have run as 64-bit and all modern machines are likely to have a 64-bit processor architecture. It would seem likely that Microsoft's rationale for this decision is simply that a 32-bit application may consume less resources.

An application running in 32-bit mode will only be able to access 2 GB of memory by default (there is a setting to increase this to 3 GB). Many of our applications may need to use more memory than this at peak times. Once the memory limit has been reached any further requests for memory will result in an OutOfMemoryException being thrown. As a consequence we recommend to untick this settings so our applications run in 64-bit mode by default.

Unfortunately when switched on this setting doesn't initially appear in the Visual Studio .csproj file, although it does appear if switched off and subsequently switched back on again. The following lines of Powershell search recursively from the current directory for C# Projects that appear to have this switch turned on:

$projFiles = (gci . -Recurse *.csproj)
$exes = $projFiles | Where-Object { !($_ | select-string "<OutputType>Library<" -Quiet) }
$dotNet45Exes = $exes | Where-Object { $_ | Select-String "<TargetFrameworkVersion>v4.5" -
Quiet }  
$dotNet45ExesWith32bit = $dotNet45Exes | Where-Object { !($_ | Select-String 
"<Prefer32Bit>false</Prefer32Bit>" -Quiet) }  
$dotNet45ExesWith32bit | ft -Property FullName 

It is possible to change an executable to remove the flag to prefer 32-bit using the command:

CorFlags.exe MyApplication.exe /32BITPREF-  

Running this command without the /32BITPREF- lists the current flag settings. The CorFlags utility is installed with the Windows SDK which can be downloaded free from Microsoft.

comments powered by Disqus