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;

[code language=”xml”]
<?xml version ="1.0"?>
<configuration>
<runtime>
<generatePublisherEvidence enabled="false"/>
</runtime>
<startup useLegacyV2RuntimeActivationPolicy="true">
<supportedRuntime version="v4.0"/>
</startup>
</configuration>
[/code]

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.0Abin\NETFX 4.0 Tools (for x86 systems)

c:\Program Files (x86)\Microsoft SDKs\Windows\v8.0Abin\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\Windowsv\v8.1A\bin\NETFX 4.5.1 Tools (for x86 systems)

C:\Program Files (x86)\Microsoft SDKs\Windows\v8.1A\bin\NETFX 4.5.1 Tools (for x64 systems)

Edit – 01-03-16:

The x64 location can also be found in a nested x64 directory within the x86 path…

For .Net 4.5.1 Projects, the sgen.exe.config file can be found at;

c:Program Files\Microsoft SDKs\Windowsv\v8.1A\bin\NETFX 4.5.1 Tools (for x86 systems)

c:Program Files\Microsoft SDKs\Windowsv\v8.1A\bin\NETFX 4.5.1 Tools\x64 (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.

By |2016-03-01T15:18:00+00:00June 7th, 2013|.Net Framework, Bugs, Tips, Visual Studio, XML|0 Comments

About the Author:

Leave A Comment