Search code examples
c#.netbuildtarget

What is the difference between a C# build for a 'x64' or 'Any CPU' target?


I am building a C# project for a DLL that will be used in an x64 environment. Originally I was using 'Any CPU" as the platform target.

However, when I test it I found it failed during library loading and I found it loaded some 32 bit libraries. I changed it to 'x64' and everything works as expected. In what case should I use 'x64' and in what case I should use 'Any CPU'?

I used to think 'Any CPU' is safer and it will automatically determine whether 32-bit or 64-bit library is required.


Solution

  • The answer to this I believe lies in the specification of the environment the program is going to be run on. You can find this out by looking at your operating system.

    Since you said in your comment that it's an EXE file (Windows), you can go into system information and look at the system type. If you want it to run on an x64 environment then use x64 and keep doing what you're doing. Your question is detailed enough that it almost answers itself.