27 March 2014

Resolve Visual Studio Project Mismatch Between Processor Architecture

The Problem

Starting in Visual Studio 2012, you may have seen this .NET Framework compiler warning (it is not an error):
There was a mismatch between the processor architecture of the project being built "MSIL" and the processor architecture of the reference [project path], "AMD64". This mismatch may cause runtime failures. Please consider changing the targeted processor architecture of your project through the Configuration Manager so as to align the processor architectures between your project and references, or take a dependency on references with a processor architecture that matches the targeted processor architecture of your project.
This is easy to resolve! The warning means one of two things:

  1. The target CPU platform (x86, x64, Itanium, etc.) of one or more projects does not match the others
  2. A referenced resource (DLL) is compiled for a different CPU platform than the referring project
Fixing the problem is easy:
  1. Ensure all projects in the solution are set to the same CPU platform target
  2. Ensure projects referencing DLL files are set to the same CPU platform as the DLL

Troubleshooting


QUESTION:
What is the difference between Any CPU, x86, and x64 (and Itanum)?

ANSWER:
These names refer to the instructions that are physically wired into the CPU.

  • The x86 instruction was created in 1978 with a 16-bit memory addressing system. Yeah, it's pretty dusty, but it works well. It has long since been extended to 32-bit, backward compatible to 16-bit. x64 and Itanium are backward-compatible to x86.
     
  • The x64 (also know as x86_64 and AMD64) instruction set is simply the 64-bit version of the x86 instruction set. Additional registers are made availalble in x64, that meet the demands of modern applications and digital media.
     
  • The Itanium (formerly called IA-64) instruction set is found in high-end enterprise quality servers that are very powerful. Support for the Itanium processor started evaporating in 2007, and Microsoft started phasing out support, in 2010, which is why Visual Studio 2012 and newer do not have this platform as a processor option. When building applications for servers, be sure to ask the system administrator which processor type of the hardware you will be using. Target Itanium, if it is available, and your Visual Studio supports it. Otherwise, use x64.
You can learn more about build platforms in the MSDN Library.



QUESTION:
Which platform target should I choose?

ANSWER:
It depends on the type of product you are creating. Generally speaking, you want to match the processor architecture as closely as possible. This means you should prefer x64 over x86, when you are reasonably sure users will be on x64 architecture. As of writing this article, most persona, computers in current use are x64, and unless the business is way behind the times (it happens more often than you think), about 80% of businesses are also running x64 instead of x86. Also, remember that 32-bit operating systems are often loaded onto x64 hardware; so, be sure to check the OS, too.

  • If it's a line-of-business application in a business that has consistent hardware configurations, select the platform that matches your company's hardware and operating system.
     
  • The majority of Microsoft Windows servers are  x64 or Itanium. Therefore, these are the best option for server-resident software.
     
  • Consumer products are a lot more sketchy. Using the "Any CPU" option is a good fallback. If your application performs any significant amount of data processing, consider offering separate 64-bit and 32-bit installation files, and let the consumer decide.



QUESTION:
I am building server software, and need to target the Itanium instruction set; but, Visual Studio 2012 only offers x86 and x64. What do I do?

ANSWER:
Apparently, you can modify the target framework and platform toolset, to enable the Itanium platform. See the How to: Modify the Target Framework and Platform Toolset page in the MSDN Library. According to this StackOverflow.com post, you must set the Platform Toolset option to v100, to enable Itanium.

3 comments:

  1. hi, i've the same problem as above ( There was a mismatch between the processor architecture of the project being built "MSIL" ) but could not resolve it..pls help

    ReplyDelete
    Replies
    1. manage to edit the webconfig to show errors in the browser..and it prompts

      Could not load file or assembly 'Oracle.DataAccess' or one of its dependencies. An attempt was made to load a program with an incorrect format

      Delete
    2. Which processor profile are you using?

      Are all projects set to use the same?

      Does that match the Oravle.DataAccess Dll?

      What dependencies does the Oracle dll have?

      Delete

Please provide details, when posting technical comments. If you find an error in sample code or have found bad information/misinformation in a post, please e-mail me details, so I can make corrections as quickly as possible.