3

I have an assembly that works perfectly when using the .Net framework 3.5 but when using it in 4 it gives an error that the assembly couldn't be loaded. Does anyone know a solution to this problem ? (I can't change the assembly in anyway or change the projects target framework because this would remove the purpose of the application) Programing code is c#.

Basicly : I'm creating an application in the .Net 4 framework but the assembly isn't compatible with it.

Following error : Assembly with mixed modus is created with version v2.0.50727 from runtime and can't be loaded without extra configuration information in runtime version 4.0.

Metabie
  • 77
  • 1
  • 6
  • 2
    What's the **exact** error message? – RB. Apr 27 '12 at 08:23
  • "Assembly met gemengde modus is gemaakt met versie v2.0.50727 van de runtime en kan niet zonder aanvullende configuratie-informatie worden geladen in de runtime van versie 4.0." Translated : Assembly with mixed modus is created with version v2.0.50727 from runtime and can't be loaded without extra configuration information in runtime version 4.0 – Metabie Apr 27 '12 at 08:31

1 Answers1

6

The best would probably be to recompile your class library for .NET 4.0 in Visual Studio 2010 (ie. opening up the project, converting it, and changing the target framework.)

If you can't, or won't, do that, then you can try adding the following to your app.config file for your .NET 4.0 application:

Add this configuration in app.config.

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

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 3.5 assemblies without specifying this in app.config.

Romil Kumar Jain
  • 20,239
  • 9
  • 63
  • 92