-1

I have several Windows Services that target 32-bit but have been running on a 64-bit OS. I want to benefit from the advantages of 64-bit processes, specifically from a memory standpoint. Outside of changing the platform target from 32 bit to 64 bit, is there anything else I need to do or watch out for?

Brian David Berman
  • 7,514
  • 26
  • 77
  • 144
  • 1
    If you're using strictly managed resources, the transition should be pretty painless. If you're referencing outside unmanaged libraries, you may run into some issues. As always, YMMV. Test it if you want to know for certain. – Glorin Oakenfoot Aug 03 '16 at 19:33
  • 1
    Switch to AnyCPU. That way you don't need to compile two times. – usr Aug 03 '16 at 19:33

2 Answers2

1

Just ensure that all references you use in your Windows Services are also compiled under 'Any' target, otherwhise you will face a problem when trying to load 32bit assemblies in a 64bit Service.

1

The answer is - depends. You said:

I have several Windows Services that target 32-bit but have been running on a 64-bit OS

If you build your app targeting x86 - you still run 32-bit even on 64-bit machine.

If you will build your service for AnyCPU, your exe will behave as following:

  • on 32 bit systems it will attempt to load as x86 and all components must be either x86 or AnyCpu

  • on 64 bit systems it will attempt to load x86-built assembly as x86 and all components MUST be only x86. And if you have some COM or 3rd party - you may have to compile for x86

  • on 64 bit systems it will load AnyCPU into x64 context and you better have NO dependencies built for x86. Also, you can build for x64, optimized code.

So, to answer your concrete original sentence - you will need (at minimum) to target AnyCPU or x64 in order to run your app in x64 context. If it is built targeting x86 - you are still running in 32 bit context

T.S.
  • 18,195
  • 11
  • 58
  • 78
  • I'm in .NET 4.5+ "Any CPU - favor 32bit" mode. Do I just need to uncheck the "favor 32-bit" checkbox – Brian David Berman Aug 04 '16 at 03:18
  • @BrianDavidBerman Yes- it runs 32 bit as you have it now. And here is answer why http://stackoverflow.com/a/12066861/1704458 – T.S. Aug 04 '16 at 13:27
  • Thanks! I'm confused by the answer you linked to since none of the configurations seem to lead to a 64-bit process. – Brian David Berman Aug 04 '16 at 13:34
  • 1
    @BrianDavidBerman I think, my answer is pretty clear about what you need to run x64 code. - all components must be AnyCPU (no additional options) or x64 – T.S. Aug 04 '16 at 13:48