Mixed mode assembly Error After Upgrading to DotNet 4.0

After upgrading existing DotNet 2.0 or 3.5 application to DotNet 4.0, you might see following error message

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.

To fix this issue, put a config file next to your exe called <exename>.exe.config with the following content:

<configuration>
<startup useLegacyV2RuntimeActivationPolicy=”true”>
<supportedRuntime version=”v4.0″/>
</startup>
</configuration>

Or if your exe already has config file, you can just append <startup> element section. To know more detail, check out Mark Miller’s post What is useLegacyV2RuntimeActivationPolicy for?

Update – 2011/11/15.

Just hit a similar issue today when I referrence SMO in a DotNet 4 Executable

Microsoft.SqlServer.Management.Dac.DacException: Unable to install DacInstance. Please verify the components of the application. —> System.IO.FileLoadException: 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.

The solution is same – in app.config file of the executable, add the following settings:

<configuration>
<startup useLegacyV2RuntimeActivationPolicy=”true”>
<supportedRuntime version=”v4.0″/>
</startup>
</configuration>


Comments

8 responses to “Mixed mode assembly Error After Upgrading to DotNet 4.0”

Leave a Reply