title: .NET application loading mixed dll, using Any CPU
body: <p>I am new to creating .NET applications, esp mixed applications. </p>
  
  <p>Recently I have created a set of (static) libraries for a client in (unmanaged) C++ (under MS Visual Studio 2010), supporting both 32-bit and 64-bit compiles, which were loaded by some applications, and which generally was fine. (Internally this functionality is using various other third party libraries, like OpenGL, boost, glm, etc)</p>
  
  <p>Now he would like to be able to also use some of the functionality that I provided as a custom control in his C# application.</p>
  
  <p>So I created a dll with CLR support, using C++/CLI to create wrapper classes for my functionality, then went to create a custom WPF control which is public (and therefore can be accessed from outside), again it works fine to build in both 32 and 64 bit.</p>
  
  <p>Then for testing I created a simple C# application (and it's really quite simple, as I am new to C#, my background is C/C++), which can be built in 32 or 64 bit, and can successfully load the control from my DLL and do what it is expected to do.</p>
  
  <p>The problem I now have is that he said he wants to be able to only distribute a single executable as "Any CPU" which should then load the appropriate code (ie 32 or 64 bit) depending on where it is launched.</p>
  
  <p>So what I did was add an "Any CPU" configuration to the C# test project, and set the "platform target" under the "build" tab to "Any CPU". But now I am not sure under Configuration Manager what platform to set for the other projects (ie the C++ static libs, consumed by the C++/CLI mixed mode dll). So for testing I left it at x64, but when I build it I get the warning:</p>
  
  <pre><code>Warning MSB3270: There was a mismatch between the processor architecture of the project being built "MSIL" and the processor architecture of the reference "(name of my 64 bit dll)", "AMD64".  &lt;br /&gt; 
  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.
  </code></pre>
  
  <p>It runs fine however, even though it gives me that warning. I get the same warning when I set my other projects to "Win32", just mentioning "x86" instead, but in that case it throws an exception on startup saying "An unhandled exception of type 'System.BadImageFormatException' occurred in PresentationCore.dll"</p>
  
  <p>So what do I need to change it to? How can I make it load the executable and then decide which dll to load? I am really not sure how to proceed and get it to work in the way that was requested of me.</p>