5

I have a simple C# console application built using Visual Studio 2012 and .NET 4.5.

When I build the solution on my 64 bit Windows 7 machine and then copy the MyProgram.exe file from this location:

C:\Users\me\Desktop\MyProgram\MyProgram\bin\x86

to a Windows XP machine, and then try to run the MyProgram.exe file, I get the following error:

MyProgram.exe is not a valid win32 application

I can see by just Googling the problem that lots of other people have the same issue and there are many suggested solutions. But none of the solutions seem to help me.

Can someone please give me step-by-step instructions for how to prepare the .exe file to run on XP?

Zolt
  • 2,761
  • 8
  • 43
  • 60
  • Is your Windows XP installation 64 bit? – Corey Ogburn Dec 16 '13 at 22:36
  • Have you tried changing the Platform Target option within Project > *your project name* Properties > Build? – valsidalv Dec 16 '13 at 22:36
  • Do you have .Net 4.5 installed on your WinXP box? – Corey Ogburn Dec 16 '13 at 22:37
  • When I look inside 'Optional Header' of an .NET exe compiled in Visual Studio 2012, the Minimum OS field is set to greater or equal to Windows Vista. Make sure you use XP supporting toolchain by going to Project Properties->Configuration Properties->General->Platform Toolset and make the value XP compatible. – Sanjeev Dec 16 '13 at 22:45
  • possible duplicate of [Is it possible to run a .net 4.5 app on XP?](http://stackoverflow.com/questions/17499351/is-it-possible-to-run-a-net-4-5-app-on-xp) – Hans Passant Dec 16 '13 at 22:54

3 Answers3

5

The steps I used (without creating a new project):

  1. Open the project settings, choose Application.
  2. On "Target framework", choose .Net Framework 4.
  3. Recompile

That's it.

Remember to also set the Publish (one-click) setting under "Prerequisites" to use Framework 4, if you're using the publish feature. I found the client version of the framework doesn't seem to cut it, you need the full version despite what the documentation seems to indicate, but maybe that's on a project-by-project basis.

Nerf Herder
  • 416
  • 3
  • 11
3

I finally got it to work!! All this time trying to figure out how to fix the problem and the solution was having to recreate the entire project from scratch.

For anyone is this same situation, save yourself the time and headache and do the following:

  1. Save and close all instances of VS2012.
  2. Start a completely new instance of VS, and target .NET 4.0.
  3. Before doing anything else, go into the configuration manager and target x86.
  4. Now copy your old code into this project.
  5. Compile and run on XP.
  6. Done!
Zolt
  • 2,761
  • 8
  • 43
  • 60
0

Programs compiled in Windows Vista and later cannot be run in Windows XP.

http://blogs.msdn.com/b/vcblog/archive/2012/06/15/10320645.aspx

You need to set the compiler to VC2010, and make sure you compile in 'release' mode to make sure the program can be run in another machine.

Mahonri Moriancumer
  • 5,993
  • 2
  • 18
  • 28
ihsanberahim
  • 1,051
  • 12
  • 14