Reputation: 11
I have a C# project in VS12/WIN7 but when I try to run it under windows server 2003, it throws an error that it's not a valid WIN32 application. I have tried many configuration, also changed to Any Cpu from Configuration Manager, but it won't work. This project has some socket and threading code... How do I fix it ?
Upvotes: 0
Views: 1794
Reputation: 283733
Try using editbin
to change the minimum required OS version. That should fix the image-not-recognized issue; but you may run into other problems later.
For example:
EDITBIN myapp.exe /SUBSYSTEM:WINDOWS,5.01 /OSVERSION:5.1
Note: This doesn't address the root cause, so it shouldn't be treated as a final solution. It is, however, the best way to determine whether the failure is caused by the "minimum required OS" field in the executable header. Also, by continuing past that check to the actual startup code of the process, it may uncover the reason that the executable was marked to require a particular Windows version.
Really, it is a bad idea for any toolchain to use the "minimum required OS" field, because the defacto meaning of that field is "display a message about an invalid image". And the number of deployed copies of Windows versions up to and including XP effectively make it impossible to restore the intended meaning (it's not feasible to patch all of them with a better error message).
A version check and meaningful error message during application startup is far better.
Upvotes: -1
Reputation: 613302
Judging by the comments to Ben's answer, you are targeting .net 4.5. This is your problem. The issue is that .net 4.5 is not supported on Windows Server 2003.
Since you need to target Server 2003, you need to target a .net version that supports that OS. The highest .net version to support Server 2003 is .net 4.
So you should change the project settings in Visual Studio to target .net 4. This MSDN article describes how to do that in Visual Studio. In summary you open the projet properties, navigate to the Application page, and set the target framework drop down.
Upvotes: 1
Reputation: 33381
If there is no bit-ness problem as mentioned in OP then you must check to which .NET version targeting your project and try to install appropriate version on Windows server 2003. Or target (if it is possible) to the version of .NET which is available on Windows server 2003 machine.
Upvotes: 1