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

As a title, I am building a C # application using VS 2012 on a 64-bit machine. I would like the program to be built to run on a 32-bit machine.

Currently, the only help I found on the Internet is: Menu> Build> Configuration> The default Active Solution platform for any processor, and I tried this, but it didn’t work on a 32-bit machine (unless I did that something wrong)

Tried to add new to x86 platform Debug configuration with build check

An application compiled and running on a 32-bit machine that received an A.exe error is not a valid Win32 application.

My above was like what was done here: Stack Overflow Link A similar question

UPDATE 1: The target OS is WinXP SP3, but we do not believe that it has .NET 4.5. I will test to decide whether compiling the previous version of the application in .NET 4.0 will resolve the problem. Perhaps the problem is not the error message being displayed.

+4
source share
5 answers

This error is a Win32 ERROR_BAD_EXE_FORMAT . It is generated by the bootloader, and this happens when you try to run a 64-bit process on a 32-bit operating system. There are other ways to see this error, but this is by far the most common reason for it to occur in a .exe file.

To compile a 32-bit process, you need to target x86 in your project configuration. Another alternative would be to target AnyCPU. This will result in a 32-bit process when executed on a 32-bit OS and a 64-bit process when executed on a 64-bit OS. It looks like your x64 build targets.

+3
source

Setting your project to targeting AnyCPU should allow it to run on a 32-bit machine, provided that you are not using a library that loads 64-bit native code. If you have any dependencies, you should also use AnyCPU or 32-bit versions of these dependencies. Also, make sure that the standard .NET Framework is installed on the 32-bit machine (.NET 4.5 by default if you are using VS 2012 with a new project).

Please note that by default in VS 2012 for new projects there is AnyCPU, with the Prefer 32 Bit option. This will lead to the fact that it will always work as a 32-bit application, even on your 64-bit OS.


Please note that since your friend works with XP sp3, you cannot use .NET 4.5..NET 4.5 is not supported on Windows XP. You will need to change the application to the target .NET 4.0, which will then work on the XP computer (if it installs the 4.0 framework).

+5
source

The platform name (shown at the top of the properties, Assembly page) is just the name. The same goes for the "Active Solution Platform" in the configuration editor. This is a bit confusing.

You need to make sure that the "Target platform" setting is indeed set to "AnyCPU" or "x86".

+1
source

I had the same problem. I struggle with that. and i found a solution. Decision:

First select the " x86 " platform. After that, create your project as a " release mode " not a " debug mode ". finally, you can work on any platform (32 bit or 64 bit).

+1
source

If none of the above solutions help you, try the following: Open the project properties and click "General" in the left column. Change the Platform Toolset to the one in which Windows XP is installed.

For example, in Visual Studio 2015, the default value is "Visual Studio 2015 (v140)." To be able to run on Windows XP, you must change this to "Visual Studio 2015 - Windows XP (v140_xp)".

Now do a full rebuild and exe should work on Windows XP.

0
source

All Articles