Click here to Skip to main content
15,882,017 members
Please Sign up or sign in to vote.
2.00/5 (1 vote)
Hi,

My requirement is to create a 64 bit application in Visual Studio 2012. I changed the target platform in project properties to x64.

As I can see the solution works fine when I set target platform to Any CPU or x86, but on selecting x64 it gives me the following error on runtime.

The error is:
Could not load file or assembly 'Demo64bitCheck' or one of its dependencies. An attempt was made to load a program with an incorrect format

Can anyone please help me with this issue.

Thanks
Posted
Comments
Sergey Alexandrovich Kryukov 23-Sep-13 11:46am    
Not clear: 1) what exactly is the architecture of the system you used? 2) what is the target architecture of each and every assembly and module used by your application?
—SA

1 solution

There is no reason to set the Platform to a particular instruction-set architecture it "Any CPU" works. .NET is based in JIT compilation, so the application will be executed on the platform determined during runtime. Please see:
http://en.wikipedia.org/wiki/Instruction_set[^],
http://en.wikipedia.org/wiki/Just-in-time_compilation[^].

You need to use other platforms only when you have at least one assembly or an unmanaged modules compiled to some particular architecture. But in this case, all target platforms should be consistent. For example, you could have all assemblies compiled to "Any CPU", and your entry-level assembly compiled to some particular architecture, because, for example. some unmanaged module is compiled to that. And any other assembly used in application should be compiled as "Any CPU" or to the same architecture. If you have any mismatch in the platforms, it won't work.

Also, you should understand that x86 will work on any of the 64-bit platforms, via WoW64: http://en.wikipedia.org/wiki/WoW64[^].

At the same time, the 64-bit platforms are incompatible with each other. There is no just "64-bit" platform, they are different and cannot be mixed up. Please see:
http://en.wikipedia.org/wiki/Itanium[^],
http://en.wikipedia.org/wiki/X86-64[^],
http://en.wikipedia.org/wiki/X86[^].

If "Any CPU" works, use just it and consider your requirement met. :-)

—SA
 
Share this answer
 
Comments
sagar wasule 23-Sep-13 15:06pm    
Hi SA thanxs for your response... I agree with you and even my code is working fine with 'Any CPU' platform. But the requirement of my application is to make it 64 bit. I double verified all the target frameworks and saw that all the projects in my application has target platform set to 64 bit ie x64. I want to run this application on 64 bit platform hence want to convert this application to 64 bit. Hence using x64.
Sergey Alexandrovich Kryukov 23-Sep-13 15:39pm    
I answered. What's the problem? And I explained that you cannot have the requirement to "make it 64 bit". You can have requirement for platform compatibility. The application is made "64-bit" when you simply execute it on some 64-bit platform. Compilation to any particular platform when "Any CPU" works would mean degrading quality of a product without any reason, that is, essentially a sabotage.
Anyway, will you accept my answer formally?
—SA

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900