HiveBrain v1.2.0
Get Started
← Back to all entries
patterncsharpCritical

What 'additional configuration' is necessary to reference a .NET 2.0 mixed mode assembly in a .NET 4.0 project?

Submitted by: @import:stackoverflow-api··
0
Viewed 0 times
netprojectmodenecessaryconfigurationadditionalassemblymixedwhatreference

Problem

I have a project in which I'd like to use some of the .NET 4.0 features but a core requirement is that I can use the System.Data.SQLite framework which is compiled against 2.X. I see mention of this being possible such as the accepted answer here but I don't see how to actually achieve this.

When I just try and run my 4.0 project while referencing the 2.X assembly I get:


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.

What "additional configuration" is necessary?

Solution

In order to use a CLR 2.0 mixed mode assembly, you need to modify your App.Config file to include:

  useLegacyV2RuntimeActivationPolicy="true">      


The key is the useLegacyV2RuntimeActivationPolicy flag. This causes the CLR to use the latest version (4.0) to load your mixed mode assembly. Without this, it will not work.

Note that this only matters for mixed mode (C++/CLI) assemblies. You can load all managed CLR 2 assemblies without specifying this in app.config.

Code Snippets

<?xml version="1.0"?><configuration>  <startup useLegacyV2RuntimeActivationPolicy="true">    <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0"/>  </startup></configuration>

Context

Stack Overflow Q#2455654, score: 692

Revisions (0)

No revisions yet.