Friday, 7 June 2013

SGEN: Mixed mode assembly is built against version 'v2.0.50727'…

I found while building an VB application in Visual Studio 2012, in release mode for the first time, that I was confronted with cryptic build error;
SGEN: Mixed mode assembly is built against version 'v2.0.50727' of the runtime and cannot be loaded in the 4.0 runtime without additional configuration information.
After trawling through some Google results, I found the following post by Microsoft;

http://social.msdn.microsoft.com/Forums/en-US/clr/thread/2a5bf31e-df96-4bf1-a846-699da46b62fb

And also a couple of forums;

http://stackoverflow.com/questions/3749368/team-build-sgen-mixed-mode-assembly
http://social.msdn.microsoft.com/Forums/en-US/clr/thread/2a5bf31e-df96-4bf1-a846-699da46b62fb

Which suggests adding (or creating if it it doesn’t exist already) the following XML to the sgen.exe.config file;
<?xml version ="1.0"?>

<configuration>

    <startup useLegacyV2RuntimeActivationPolicy="true">

                <supportedRuntime version="v4.0" />

    </startup>   

</configuration>
For .Net 4.0 Projects, the sgen.exe.config file can be found at;
c:\Program Files\Microsoft SDKs\Windows\v7.0A\bin\NETFX 4.0 Tools  (for x86 systems) 
c:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\bin\NETFX 4.0 Tools (for x64 systems)
For .Net 4.5 Projects, the sgen.exe.config file can be found at;
c:\Program Files\Microsoft SDKs\Windows\v8.0A\bin\NETFX 4.0 Tools (for x86 systems) 
c:\Program Files (x86)\Microsoft SDKs\Windows\v8.0A\bin\NETFX 4.0 Tools (for x64 systems)
Edit - 03-06-14:

For .Net 4.5.1 Projects, the sgen.exe.config file can be found at;
c:\Program Files\Microsoft SDKs\Windows\v8.0A\bin\NETFX 4.5.1 Tools (for x86 systems) 
c:\Program Files (x86)\Microsoft SDKs\Windows\v8.0A\bin\NETFX 4.5.1 Tools (for x64 systems)
Once I’d added the xml, the application built just fine.

The other alternative was to disable the option to Generate Serialization Assemblies in the offending project;

  • Project Settings for the offending Project
  • Compile Tab
  • Advance Compile Options Button
  • Set “Generate Serialization Assemblies” from “Auto” to “Off”

However, I recommend that you go with the XML option as suggested by Microsoft.

No comments:

Post a Comment