Looks like there are many similar problems without good explanation.
Environment:
Win 7
VS2012 Pro
Windows SDK 7.0
In our environment we generate 2 code bases - x86 and x64. For this specific project we generate *.XMlSerializers.dll
. The setting in the build for Generate Serialization Assemblies is Auto
.
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:
I used procmon
from sysinternals
to trace SGEN
C:\Program Files\Microsoft SDKs\Windows\v7.0\Bin
(32-bit sngen.exe)I set project configuration to create serializers to OFF and compiled assembly in x64. Then I tried a command line
C:\Program Files\Microsoft SDKs\Windows\v7.0\Bin\x64
- (please note - this is 64-bit sgen.exe)These results lead to a conclusion: When VS2012 compiles a project with Generate Serialization Assemblies set to ON (auto is a special case), it attempts to find sgen.exe. But when your project configuration is set to build for x64 platform, it fails to find appropriate sgen.exe, one that itself was built for x64.
Question: Is there msbuild configuration or registry setting, or something else there, that can be set to allow Visual Studio find appropriate SGEN?
I know about workarounds, i.e. Post Build events and turning it off but this is not the point.
Generally speaking, one could add this XML into specific configuration in the project file, and this will point to specific sgen.exe
that you want.
<SGenToolPath>C:\Program Files\Microsoft SDKs\Windows\v7.0\Bin\x64</SGenToolPath>
But to solve my issue in a broader, environment-specific way I had to set Generate Serialization Assembly to OFF and use separate command line action post-build
"path to your specific\sgen.exe" "path\yourFile.dll" /f
I had to do it this way because many developers here use different versions of VS studio, etc. They set their machines and who knows what and where they install. So, I added a specific action to a build process to perform this step separately because I know exactly where specific sgen.exe
is located on build server.