Reputation: 3264
I am working with visual studio 2010, .NET 4.0 and WPF. We are trying to build the project with platform as "AnyCPU" which will make the program platform neutral. In the middle of doing so I started confusing myself.
I thought all the .NET programs target .NET framework instead of the operating system. If that is the case I should not worry about whether I am working on a "x64" or "x86" system. All that program target is .NET framework which is a proper "Run Time" which will take care of itself. The CLR can allocate memory according to the platform it is sitting on, but the .NET projects shouldnt worry about that.
What am I missing here? What is the point of "platform " in build settings in .NET projects?
Upvotes: 4
Views: 538
Reputation: 1900
As others have mentioned, when you use other libraries that are built for a specific platform, you may need to specify that platform. One good example is COM.
Lets say you have a 32 bit COM component (which most are), and the client OS is 32 bit. If you compile for "AnyCPU", it will work fine, because it will JIT to native x86 code since you are running on a 32 bit system.
Now lets say you have the same COM component and the client OS is 64 bit. On windows, when the COM component gets registered, it will be registered in the 32 bit section of the registry (WOW6432Node i think). So if you have your app compiled for "AnyCPU", it will be a native 64 bit app and not be able to invoke you COM component (resulting in class not registered) since it will look in the 64 bit registry. You will get the same error if you compile for x64 (since it results in the same native code after JIT.) But if you compile for x86, it will work fine.
Upvotes: 4
Reputation: 6639
As CodeInChaos said, it's a question of library. Under x64, you can't use x86 libraries. Under x86, you can run x64 libraries.
Any cpu
means it will use your current platform settings (running cpu).
If you want to read more detailed about it, here is a good reading: http://visualstudiohacks.com/articles/...
Upvotes: 1
Reputation: 108800
One common reason to restrict yourself to one architecture is that you use native libraries that only support one platform.
For example in one of my projects I included libvorbis
and I was too lazy to compile a 64 bit version of it. So I just set my project to 32 bit only. Some other native libraries might not support 64 bits at all, especially if they are closed source legacy components.
Upvotes: 4