title: WcfSvcHost BadImageFormatException when executing WCF service application
body: <p>OK, I am building a client server application using WCF with NetTcpBinding hosted and consumed by  a WinForms application. I am using VS.2012 Ultimate in Windows 7 Ultimate x64.</p>
  
  <p>I can start the winform that hosts the service and I can start the service. Now, on the client side I start the client application and immediately get a Microsoft WCF Service Host window telling me:</p>
  
  <pre><code>System.BadImageFormatException. Could not load file or assembly X.Services.dll ... an
  attempt was made to load a program with an incorrect format.
  at System.Reflection.RuntimeAssembly._nLoad(AssemblyName fileName, String codeBase, Evidence assemblySecurity, RuntimeAssembly locationHint, StackCrawlMark&amp; stackMark, IntPtr pPrivHostBinder, Boolean throwOnFileNotFound, Boolean forIntrospection, Boolean suppressSecurityChecks)
  at System.Reflection.RuntimeAssembly.InternalLoadAssemblyName(AssemblyName assemblyRef, Evidence assemblySecurity, RuntimeAssembly reqAssembly, StackCrawlMark&amp; stackMark, IntPtr pPrivHostBinder, Boolean throwOnFileNotFound, Boolean forIntrospection, Boolean suppressSecurityChecks)
  at System.Reflection.Assembly.Load(AssemblyName assemblyRef)
  at Microsoft.Tools.SvcHost.ServiceHostHelper.LoadServiceAssembly(String svcAssemblyPath)
  </code></pre>
  
  <p>Now, both the client and server WinForm projects have a reference to the X.Services.dll which defines the services (Interface &amp; implementing class). So, why does the server doesn't complain about it?</p>
  
  <p>Also, I have made sure that ALL the projects in this solution have BOTH their Debug &amp; Release configurations set to the same .NET Framework (4.5) and the SAME target platform (x86 instead of Any CPU).</p>
  
  <p>Additionally, the only external assembly reference (a utility library DLL) is ALSO built with the same VS version, for the same framework (4.5) AND the same platform (x86).</p>
  
  <p>So where does this bad image format comes from? The solution has its own copy of the external library (to make sure it has the right platform &amp; framework configuration) and the project files have been modified so that it takes the corresponding Release/Debug version of the external assembly.</p>
  
  <p>Following a hint from the exception I used regedit to add a key in HKLM to enable assembly load/binding logging and got this extra information:</p>
  
  <pre><code>=== Pre-bind state information ===
  LOG: User = DOMAIN\Username
  LOG: Where-ref bind. Location =    D:\Sources\My.Net\Code\T\X.Services\bin\Debug\X.Services.dll
  LOG: Appbase = file:///D:\Sources\My.Net\Code\T\X.Services\bin\Debug\X.Services/bin/Debug
  LOG: Initial PrivatePath = NULL
  Calling assembly : (Unknown).
  ===
  LOG: This bind starts in LoadFrom load context.
  WRN: Native image will not be probed in LoadFrom context. Native image will only be      probed in default load context, like with Assembly.Load().
  LOG: Using application configuration file: D:\Sources\My.Net\Code\T\X.Services\bin\Debug\X.Services.dll.config
  LOG: Using host configuration file: 
  LOG: Using machine configuration file from  C:\Windows\Microsoft.NET\Framework64\v4.0.30319\config\machine.config.
  LOG: Attempting download of new URL file:///D:\Sources\My.Net\Code\T\X.Services\bin\Debug\X.Services.dll.
  ERR: Failed to complete setup of assembly (hr = 0x8007000b). Probing terminated.
  </code></pre>
  
  <p>which to me doesn't tell me anything of use...</p>