2
votes

We have a windows service created in .NET 2.0. I've set the Platform Target to X86, and the installer to be X86. The projects it references are set to ANYCPU.

We're running this on a 64bit server. It has to be 32bit because the ODBC drivers it accesses are 32bit, and they bomb heavily if accessed from a 64bit application.

I've seen that on a 64bit machine, some processes have the *32 beside them to denote 32bit, however that doesn't seem to be the case with a test one I created that specifically targets 32bit (X86) to see if it actually was that. The service we're running does not show *32 beside the service name.

Any thoughts on this? If it is not being run as 32 bit (X86), then I'm surprised as I've forced the build to be that.


Update, We found it's running in 64bit, even though the Services project was forced to buid in X86 mode. What would cause this?

4
use corflags.exe to ask the assembly what mode it runs in.Sam Axe
@xanatos, I don't think that this is a duplicate. The OP doesn't want (despite his misleading question title) to determine if he is running in 32 bit or 64 bit mode. He wants to force 32 bit mode due to his code being dependent on ODBC.Darin Dimitrov
So, is it crashing like it should? Tick the "Show processes from all users" option in Taskmgr.exe.Hans Passant
@DarinDimitrov Considering the most upvoted answer at this time is IntPtr.Size... Perhaps the OP shoud learn to give more meaningful titles... And he isn't even sure he is running at 32 or 64 bits :-)xanatos
Yea it's bombing big time - but we wanted to see if it was because it's running as 64bit, or if there was another issue. It is running as 64bit.Ryan Ternier

4 Answers

1
votes

One plausible explanation for the discrepency is that you're deploying the output of a different build configuration.

Could it be that you setup your Debug configuration to target x86, but didn't make the change to the Release configuration, thereby leaving it as AnyCPU and deploying it to production?

6
votes

You can use IntPtr.Size (MSDN docs). This will return 4 if running as 32 bit and 8 if running as 64 bit.

4
votes

Use corflags.exe to mark your assembly as 32 bit. You can do that as a post-build step if you'd like:

corflags.exe MyProgram.exe /32Bit+

I don't have an answer to your second question (you might want to create a separate SO question for that) why the x86 project runs as a 64-bit process.

0
votes
private static bool Is64BitConfiguration()
{
     return System.IntPtr.Size == 8;
}