Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to compile 32-bit (my OS is 64-bit) - Error exe is not a valid Win32 application

As title suggests I am compiling C# app using VS 2012 on a 64-bit machine. I would like the program being built to run on a 32-bit machine.

Right now the only help I found online was for: Menu>Build>Configuration> Active Solution Platform defaulted to Any CPU, and I tried that but didn't work on 32-bit machine (unless I did something wrong)

Tried Add a new one to the Debug configuration for platform x86 with build checked

Compiled and ran the app on 32-bit machine getting error A.exe is not a valid Win32 application.

My above was similar to what was done here: Link to Stack Overflow Similar Question

UPDATE 1: The target OS is WinXP SP3 but we dont believe it has .NET 4.5 on it. I will be testing to see if compiling earlier ver of the app in .NET 4.0 will solve the problem and fix the problem. The problem may not be what the error message is displaying.

like image 313
Kairan Avatar asked Jan 31 '13 19:01

Kairan


1 Answers

Setting your project to target AnyCPU should allow it to run on a 32bit machine, provided you aren't using a library which loads 64bit native code. If you have any dependencies, you'll need to make sure to use AnyCPU or 32-bit versions of those dependencies, as well. Also, make sure you have the proper .NET Framework installed on the 32bit machine (.NET 4.5 by default, if you're using VS 2012 with a new project).

Note that the default in VS 2012 for new projects is AnyCPU, with the Prefer 32 Bit option checked. This will cause it to always run as a 32bit application, even on your 64bit OS.


Note that, since your friend is running XP sp3, you can't use .NET 4.5. .NET 4.5 is not supported on Windows XP. You will need to change your application to target .NET 4.0, which will then work on the XP machine (if he installs the 4.0 framework).

like image 141
Reed Copsey Avatar answered Sep 24 '22 17:09

Reed Copsey