title: SGEN failure: An attempt was made to load an assembly with an incorrect format in VS2008
body: <p>I was able to find several similar questions asked and answered, but none of the answers or exact conditions applied to my situation.</p>
  
  <ol>
  <li>I have a .NET 3.5 project being built for x64.</li>
  <li>I also have an x64 mixed mode reference (also targeting .NET 3.5).</li>
  <li>In Visual Studio 2008, I created a Web Reference which causes SGEN to execute during a Release build to create the helper DLL.</li>
  </ol>
  
  <p>If I don't reference the <code>mixed-mode DLL</code>, this works fine.  If I do reference the mixed mode DLL, I get this error (xxx is just a placeholder):</p>
  
  <blockquote>
    <p>SGEN : error : An attempt was made to load an assembly with an
    incorrect format:
    C:\code\xxx\trunk\xxx\common\xxx\build\winx64\lib\xxx.dll.</p>
  </blockquote>
  
  <p>This is the command being issued:</p>
  
  <blockquote>
    <p>C:\Program Files\Microsoft SDKs\Windows\v6.0A\bin\sgen.exe
    /assembly:C:\code\xxx\trunk\xxx\xxx\obj\x64\Release\xxx.dll
    /proxytypes /reference:..\common\xxx\build\winx64\lib\xxx.dll
    /reference:C:\Windows\Microsoft.NET\Framework\v2.0.50727\System.configuration.dll
    /reference:C:\Windows\Microsoft.NET\Framework\v2.0.50727\System.Configuration.Install.dll
    /reference:"C:\Program Files (x86)\Reference
    Assemblies\Microsoft\Framework\v3.5\System.Core.dll"
    /reference:C:\Windows\Microsoft.NET\Framework\v2.0.50727\System.Data.dll
    /reference:C:\Windows\Microsoft.NET\Framework\v2.0.50727\System.dll
    /reference:C:\Windows\Microsoft.NET\Framework\v2.0.50727\System.EnterpriseServices.dll
    /reference:C:\Windows\assembly\GAC_MSIL\System.Management.Automation\1.0.0.0__31bf3856ad364e35\System.Management.Automation.dll
    /reference:"C:\Program Files (x86)\Reference
    Assemblies\Microsoft\Framework\v3.0\System.Runtime.Serialization.dll"
    /reference:"C:\Program Files (x86)\Reference
    Assemblies\Microsoft\Framework\v3.0\System.ServiceModel.dll"
    /reference:"C:\Program Files (x86)\Reference
    Assemblies\Microsoft\Framework\v3.5\System.Web.Extensions.dll"
    /reference:C:\Windows\Microsoft.NET\Framework\v2.0.50727\System.Web.Services.dll
    /reference:C:\Windows\Microsoft.NET\Framework\v2.0.50727\System.Xml.dll</p>
  </blockquote>
  
  <p>Any ideas?</p>