15

I would like to know the difference between .NET modes x86 and x64.

  1. What is the difference for both modes?

  2. Can I compile my libraries for example with .NET x64 and .NET x86?

  3. Would it be any difference for me if I choose x64 instead of x86?

  4. What is the advantage of .NET x64?

  5. Do I have to install anything special if I want to use .NET x64?

bluish
  • 26,356
  • 27
  • 122
  • 180
truthseeker
  • 2,214
  • 6
  • 30
  • 53
  • 2
    Ususally, you do _not_ compile your libraries explicitely for 32 or 64 bit but for "any cpu" and let the target machine (or your main application) choose, which to run. – Uwe Keim Dec 28 '10 at 10:38
  • 2
    If you choose one mode, the app gonna be lighter but could not run on the other platform... – ykatchou Dec 28 '10 at 10:44

3 Answers3

17

Complex question, I'll try to simplify:

  1. Any .Net application can be compiled for both x86 (32-bit) and x64 (64-bit) at once. Actually they do by default. You can change this by changing target CPU in Build-tab in project Properties. Supported targets are "Any" (will Just-In-Time compile to 32 or 64-bit depending on operative system support), "x86" will compile to 32-bit which works on all platforms, and "x64" will compile to 64-bit which only works on 64-bit platforms.

  2. Yes. See above. Also note that there is a second level of compile sometimes performed, and that is the NGEN. It creates a native image for a specific CPU type. However, if you mess with this you know already.

  3. For .dll's choose "Any" CPU for them. For .EXE (entry point) you must choose Any, x86 or x64. There are some things to consider: x86 .Net apps accessing native Windows .dll-files (interpo) require x86 .dll-files. So a 64-bit app can't access 32-bit API-calls and vice versa. This is often a reason for .Net apps to fail on 64-bit operating systems. The way to solve this is to either reference correct .dll's or simply set the .Net application to x86 (32-bit) under properties. All other dependencies will automatically become 32-bit during Just-In-Time compile if they are set to "Any".

  4. The advantages of 64-bit are complex. There are advantages and drawbacks depending on what your app does. The most obvious advantage is that your application can break the 2GB memory barrier. The disadvantage is as explained in #3, if you reference 64-bit .dll's your app won't execute on 32-bit operating systems.

  5. Everything comes out-of-the-box. Don't worry about a thing, except all the stuff above. :)

Tedd Hansen
  • 12,074
  • 14
  • 61
  • 97
0
  1. If you are compiling your code for Any CPU, a x64 tries to load native, external DLLs as x64 version. That might be problematic if that DLL is 32-bit. It throws an exception.
  2. Yes, you can build it as Any CPU
  3. s. 1
  4. It (can) internally use x64 advantages of the operating system like 4GB+ memory etc.
  5. No, this is done by .NET installer by default.
bluish
  • 26,356
  • 27
  • 122
  • 180
0
  1. There are modes for 32bit or 64bit platforms (Operating Systems)
  2. Yes, you can - actually VS installs the 32 bit version of CLR on x86 computer and 32 bit and 64 bit (both of them) versions of CLR on 64 bit Windows. Since VS is 32 bit application, it runs under WOW64 on 64 bit computers.
  3. Many applications behave identically on both the 32-bit CLR and the 64-bit CLR. But, there can be some differences (for example incorrect platform invoke that use Int32 for handles instead of IntPtr)
  4. The same as advantage of 64 bit operating systems vs x86 ones
  5. If you're using 64 bit Windows and VS2010, then you have all you need to develop .net x64
Vladimir
  • 1,781
  • 13
  • 12