views:

511

answers:

3

Can a WinForms app compiled for "Any CPU" be configured to run as "x86" on a 64-bit server without recompiling the app? Specifically, I'm looking for an app.config setting or Control Panel applet to accomplish this end. All the customer's clients are x86, but the server is x64, and we like to install the WinForms app on the server for administrators to configure and monitor the system. We would much rather not recompile just for the server.

+8  A: 

From http://www.request-response.com/blog/PermaLink,guid,34966ef8-3142-46b2-84e0-372b5c36ddcc.aspx

You can, however, control and override this default behaviour even after your code has been compiled. There's a handy tool called corflags.exe present in the SDK that allows you to force 'anycpu' compiled code to use 32-bit process in 64-bit world.

The usage of this utility is found here http://msdn.microsoft.com/en-us/library/ms164699(VS.80).aspx

Rory Becker
I tried this out on our customer's server, and it worked with flying colors! Thanks. My only complaint is that it took for freaking-ever to install the Windows SDK on the Windows Server 2003 machine.
flipdoubt
You could have installed it on a development machine and altered the exe on that. :)
Rory Becker
+1  A: 

No configuration ought to be needed if you wrote your managed code correctly. As long as the 64-bit machine has the proper frameworks installed, the JIT process will take care of any of the differences between 32 and 64 bit requirements.

The only thing you need to be concerned about in your own code is if you were doing any P/Invoke. In that case, any time you call an API function that utilizes a HANDLE or void* type, you need to ensure that you always use System.IntPtr, and not System.Int32. In the .NET world, the int data type is ALWAYS 32 bits, even on a 64 bit machine. Likewise a long is always 64 bits, no matter what architecture.

And IntPtr however is always the size of void*, and so properly JIT's to different sizes depending on the architecture of the machine you're running on.

Nick
+1  A: 

I found this link helpful too: http://blogs.intesoft.net/2007/12/default.aspx

flipdoubt