title: Sgen and x64 project configuration to create XML Serializers assembly
body: <p>Looks like there are many similar problems without good explanation. </p>
  
  <p>Environment:</p>
  
  <p>Win 7</p>
  
  <p>VS2012 Pro</p>
  
  <p>Windows SDK 7.0</p>
  
  <p>In our environment we generate 2 code bases - x86 and x64. For this specific project we generate <code>*.XMlSerializers.dll</code>. The setting in the build for <em>Generate Serialization Assemblies</em> is <code>Auto</code>.</p>
  
  <p>When I compile project to x64 config, I get SGEN error "attempt load assembly in incorrect format... system.data.dll". This error is totally misleading because farther investigation brought the following results:</p>
  
  <p>I used <code>procmon</code> from <code>sysinternals</code> to trace SGEN</p>
  
  <ol>
  <li>When building for <strong>AnyCpu</strong> and <strong>x86</strong> <em>procmon</em> shows a trace. The <em>sgen</em> in use is from <code>C:\Program Files\Microsoft SDKs\Windows\v7.0\Bin</code> (32-bit sngen.exe)</li>
  <li>When building for <strong>x64</strong> there is no trace and only error mentioned above</li>
  </ol>
  
  <p>I set project configuration to create serializers to <strong>OFF</strong> and compiled assembly in x64. Then I tried a command line </p>
  
  <ol start="3">
  <li>Success came about using SGEN in <code>C:\Program Files\Microsoft SDKs\Windows\v7.0\Bin\x64</code> - (please note - this is 64-bit sgen.exe)</li>
  <li>Running 32-bit SGEN on x64 Assembly failed.</li>
  </ol>
  
  <p>These results lead to a conclusion: When VS2012 compiles a project with <em>Generate Serialization Assemblies</em> set to <strong>ON</strong> (<strong>auto</strong> is a special case), it attempts to find <strong>sgen.exe</strong>. But when your project configuration is set to build for x64 platform, it fails to find appropriate <strong>sgen.exe</strong>, one that itself was built for x64. </p>
  
  <p><strong>Question:</strong> Is there <em>msbuild</em> configuration or registry setting, or something else there, that can be set to allow Visual Studio find appropriate SGEN?</p>
  
  <p>I know about workarounds, i.e. Post Build events and turning it off but this is not the point.</p>