title: C++ CLI DLL not being loaded by IIS7 but only if built with anything newer than VS2008
body: <p>For my development environment I'm using Windows 7 Ultimate x64, with VS2008, V2010 and VS2013, and my application is written in C#.</p>
  
  <p>The remote test server has Windows Web Server 2008 R2 x64 and IIS 7.</p>
  
  <p>Here is my specific issue:</p>
  
  <p>I have a native C++ library that I want to use in my C# applications, so I wrote a C++ CLI/CLR wrapper around it, and compiled it all into the same DLL.  I've tried both compiling the C++ source into the DLL, and also statically linking the native library into the DLL, and both give me the same result as described below.</p>
  
  <p>If I build this DLL using x64 and .NET 4.5.1 with VS2013, then this DLL works fine with any C# Winforms application in and out of the development environment. It also works when referenced in an ASP.NET application within my development environment (using x64 IIS Express to test).  It does NOT work when the web application is deployed (as an x64 build) to the Win2K8 IIS7 server, displaying an BadImageFormatException. I do not build for "AnyCPU" because of the CLI wrapper DLL, which needs to be built for a specific platform.</p>
  
  <p>I have also tried the .NET4.5.1 x86 version of the CLI DLL (using VS2013), and it also works fine with all Winforms applications, and works with ASP.NET on my development machine (using x86 IIS Express), but it does not work on the Win2K8 IIS7 server (x86 build). Same BadImageFormatException error when trying to load this DLL.</p>
  
  <p>On the server it uses an integrated application pool because of the ASP.NET Identity code (won't let me use Classic mode). Also, the "32-bit applications" setting has been toggled to both True/False, and neither has helped solve this issue.</p>
  
  <p>If I build the C++ CLI DLL for .NET 2 or .NET 3.5 and the x86 platform with VS2008, or even VS2013, but selecting VS2008 (V90) as the platform toolset, then it works perfectly fine on the Win2K8 IIS7 server, with no BadImageFormatException error.  The ASP.NET integrated app pool "32-bit applications" setting is "True" in order for this to work.</p>
  
  <p>If I build the C++ CLI DLL as .NET 2 or 3.5, x86 platform, but with anything newer than the VS2008 toolset, it fails to load on the IIS server, with BadImageFormatException, even though it works fine on the development machine ASP.NET and in any Winforms application.</p>
  
  <p>Using VS2008, .NET 2 or 3.5, and platform x64, the DLL works in any Winforms app, works with ASP.NET/IIS Express x64 on the development machine, but does NOT work on the Win2K8 IIS7 server, displaying BadImageFormatException. The application pool "32-bit applications" was set to both True and False for testing.</p>
  
  <p>So, in summary, the only option that works on IIS7 is building with the x86 platform selected, using the VS2008 (V90) toolset.</p>
  
  <p>Has anyone experienced anything like this or have an idea what may be causing this issue.  I can't see anything drastically different between the working DLL and the others using JetBrains dotNetPeek 1.1, but that's only really a look at the surface... all the code exists in there.  Could there be an option in the V100 or higher toolset that is embedding something in the DLL (or leaving something out of it) that is causing it to not be loaded on IIS7?</p>
  
  <p>Any help or suggestions would be appreciated.</p>