Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using a 3.5 assembly in 4

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.

like image 775
Metabie Avatar asked Feb 16 '26 16:02

Metabie


1 Answers

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.

like image 113
Romil Kumar Jain Avatar answered Feb 19 '26 11:02

Romil Kumar Jain



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!