Why is my 64 bit service running as 32 bit?
Asked Answered
T

2

6

I have a Windows Service that I'm having this issue with.

  • In Visual Studio I've set its Platform Target to 64 bit
  • I've run CorFlags to verify that it is set correctly, I get this:
Version   : v4.0.30319
CLR Header: 2.5  
PE        : PE32+
CorFlags  : 0x1    
ILONLY    : 1       
32BITREQ  : 0        
32BITPREF : 0        
Signed    : 0

I even tried running Corflags with the 32BITREQ- and 32BITPREF- flags to make sure it was set to what it's supposed to be but no dice. In the taskManager it shows up as:

MyServiceName (32 bit)

Service was installed with Topshelf 3.0 and is running on Windows Server 2012 R2 Standard. What's going on here?

Thorsten answered 18/8, 2015 at 19:0 Comment(7)
Is it a 64-bit box? ;)Glasswort
@ 500 - Internal Server Error - Haha, yeah I didn't make that mistake fortunatelyThorsten
Are you referencing any 32-Bit libs? Do you have Prefer32Bit set to true in the .csproj?Chante
@Allan Elder I double-checked the libs, thay are all 'Language Neutral'. I also don't have that flag checkedThorsten
It isn't clear to me exactly how TopShelf works - the documentation doesn't go into much detail - but it seems likely that you need to use the 64-bit version (if there is one) in order for the service to run as a 64-bit process.Misuse
Something sounds wrong with the project settings. My understanding of platform targets is that the service should not be able to run as x86 if you set the platform target to x64 at all regardless of corflags, installutil and so on. Maybe a clean of all built files and rebuild? And hand checking of the .csproj XML to validate?Splenic
@Splenic a 32 bit application can spawn a 64 bit process with no problem. I have the feeling that the launched process is actually TopShelf, which may be running in 32 bit, and that is the one launching the 64 bit process. Should be worth looking on some better process viewer than task manager (something like Process Explorer) and see if there's your exe being launched by the 32 bit "task"Sanctitude
T
2

I had this issue when a previous version of the service had been 32 bit. I knew the currently installed one wasn't (checked CORFLAGS), but the process associated with the service was being created as 32 bit anyway, and for the life of me I couldn't work out why.

After a reboot the problem went away. I wonder if the Service Control Manager 'remembers' the bitness for each service, as a startup optimization (or something).

Tapes answered 15/2, 2017 at 7:2 Comment(0)
J
0

Maybe your installation tool is using 32 bit installutil to install the process? As I understand from this article

using 32 bit installutil results in forcing the executable to run as 32 bit in a 64 bit OS.

This part of the article in particular seems to say so:

To get around this problem, please run installutil.exe outside of the appropriate Framework/Framework64 directory. If you have a snap-in built for ILONLY (ILONLY indicates that the executable contains pure IL code and can run either as 32-bit or as a 64-bit process), but want to register it under the wow64 hive, use installutil.exe that is available in the directory %windir%\microsoft.net\framework\v2.n.n.n. For the 64-bit hive registration, run installutil.exe from the directory %windir%\microsoft.net\framework64\v2.n.n.n.

Jointress answered 18/8, 2015 at 19:16 Comment(3)
I am using Topshelf as the installer, not installutilThorsten
I was suggesting maybe Topshelf uses installutil under the hood. Couldn't find any information about this though.Theaterintheround
That article is about MMC snapins, not services. They're not related.Misuse

© 2022 - 2024 — McMap. All rights reserved.