Running a 32-bit C # application on a 64-bit machine

How to make an application run a 32-bit version on a 64-bit machine?

The code is written in C #.

+9
c # x86 x86-64 64bit
Jan 12 '09 at 22:29
source share
6 answers

Right-click your project and select properties.

In the properties, select the assembly tab. In the target platform, select x86.

Press Ctrl + Shift + S to save all the files, right-click on the solution and select "Clear" to get rid of the old binary files. Any builds after that should be 32 bits

+22
Jan 12 '09 at 22:32
source share

Command line form:

corflags application.exe /32BIT+ 
+9
Jan 15 '10 at 2:33
source share

Here's how I did it when we couldn't change the existing code from any CPU to x86 due to ClickOnce restriction:

Create 32-bit (x86 should be checked in the project properties) Application "launcher" (Windows application, but not form):

  static void Main(string[] args) { // Load the assembly string directory = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location); string assemblyName = Path.Combine(directory, "YourAnyCPUApplication.exe"); Assembly assembly = Assembly.LoadFile(assemblyName); assembly.EntryPoint.Invoke(null, null); } 

Add the following code to the Main method in the Any CPU project:

  if (IntPtr.Size == 4) { Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); // etc... } else { // Launch application in 32-bit mode System.Diagnostics.Process.Start(Path.GetDirectoryName(Application.ExecutablePath) + @"\Your32BitApplicationLauncher.exe"); } 

Hope this helps :-)

+7
Jan 15 '10 at 2:15
source share

If you go to Configuration Manager in Visual Studio, you can install the platform on x86 or x64.

+5
Jan 12 '09 at 22:32
source share

Assuming it's Winforms, a console application, or a Windows service, you need to build an exe for x86 instead of Any CPU. This is in Configuration Manager.

+1
Jan 12 '09 at 22:31
source share

Visual Studio 11 and .NET framework 4.5 or higher have the Any CPU 32-bit preferred option, and since then it has been the default

The resulting code will run on any platforms, but on 64-bit platforms they run as 32-bit processes.

0
May 10 '14 at 2:34
source share



All Articles