Captain Codeman Captain Codeman

Running .NET Apps in 32-bit mode on 64-bit Windows

Contents

Introduction

The normal behavior for .NET 2.0 applications compiled with the default ‘Any CPU’ platform is to run as 32-bit on x86 (32-bit) Windows and as 64-bit on x64 (64-bit) Windows.

Occasionally, some apps won’t run correctly - I’ve recently run into this with CCNetConfig (a CruiseControl.NET Configuration tool) and have seen it before with other tools. Another obscure scenario where it shows up is if you try to use the JET OleDB driver which will fail in 64-bit mode because there isn’t one! (it has to be 32-bit).

Rather than have to recompile the app or even worse, run a 32-bit Virtual Machine, there is an easy way to force .NET to run an app in 32-bit mode using the CorFlags.exe tool.

Depending on your system this may be installed in different places. I’ve seen it in different places on XP64 and Vista X64:

  • C:Program FilesMicrosoft SDKsWindowsv6.0Binx64CorFlags.exe
  • C:Program Files (x86)Microsoft Visual Studio 8SDKv2.0BinCorFlags.exe

Running this from the command line with the path / filename of the app you want to change and the switch /32BIT+ to turn on 32-bit mode, e.g.:

CoreFlags.exe TheApp.exe /32BIT+

If that fixes the problem then you know that it _**is **_a 64-bit issue. You can re-enable 64-bit operation for the app by turning off the 32-bit switch with the parameter /32BIT-, e.g.:

CoreFlags.exe TheApp.exe /32BIT-

Voila … control over 32-bit and 64-bit execution without doing a recompile! I’m not 100% certain but I think that this switch sets the same flag that the ‘x86’ and ‘Any CPU’ targets set in Visual Studio.