C# – Mixed mode assembly is built against ‘v2.0.50727’ error

.net-2.0.net-4.0cmixed-modenet

First of all, I've found the other posts on StackOverflow here, but it did not resolve my error.

I have 3 different environments/domains with a build server in each location. My Dev and UAT environments build just fine, but the production version does not work.

I'm getting the error

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

I've added this tag to my app.config file (which was the suggested fix in the link I have above)

  <startup useLegacyV2RuntimeActivationPolicy="true">
    <supportedRuntime version="v4.0"/>
  </startup>

What else could be different between my build servers/environments/domains that would be causing this issue?

In response to Allen's question, I believe this is what you're asking:

<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
  <PropertyGroup>
    <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
    <Platform Condition=" '$(Platform)' == '' ">x86</Platform>
    <ProductVersion>8.0.30703</ProductVersion>
    <SchemaVersion>2.0</SchemaVersion>
    <ProjectGuid>{D3D87C05-2811-489B-9F0D-7676B6485AA0}</ProjectGuid>
    <OutputType>Exe</OutputType>
    <AppDesignerFolder>Properties</AppDesignerFolder>
    <RootNamespace>MVST.Batch.CorrespondenceConversion</RootNamespace>
    <AssemblyName>MVST.Batch.CorrespondenceConversion</AssemblyName>
    <TargetFrameworkVersion>v3.5</TargetFrameworkVersion>
    <FileAlignment>512</FileAlignment>
  </PropertyGroup>

I have over 100 other projects that are setup the exact same way and those build ok.

Best Answer

http://support.microsoft.com/kb/2572158

Add the verbiage useLegacyV2RuntimeActivationPolicy="true" below either to either of the following locations:

  1. sgen.exe.config file located at the following location: ..\Program Files\Microsoft SDKs\Windows\v7.0A\bin\NETFX 4.0 Tools\
  2. The applications' app.config file

<startup useLegacyV2RuntimeActivationPolicy="true">

            <supportedRuntime version="v4.0" />

</startup>