Integrating .NET 2.0 Mixed-Mode Assemblies into .NET 4.0 Projects
Directly loading mixed-mode assemblies compiled for older .NET runtimes within newer versions (e.g., .NET 2.0 in .NET 4.0) isn't possible without specific adjustments. This necessitates additional configuration.
Configuration for Loading Mixed-Mode Assemblies
To successfully utilize a CLR 2.0 mixed-mode assembly in a .NET 4.0 project, you must modify the application's configuration file (App.Config) to include the following:
<code class="language-xml"><?xml version="1.0"?> <configuration> <startup useLegacyV2RuntimeActivationPolicy="true"> <supportedRuntime sku=".NETFramework,Version=v4.0" version="v4.0"/> </startup> </configuration></code>
The crucial element is useLegacyV2RuntimeActivationPolicy="true"
. This directive instructs the Common Language Runtime (CLR) to employ the latest version (4.0 in this case) for loading the mixed-mode assembly. Omitting this will result in a loading failure.
Important Notes
This configuration is solely applicable to mixed-mode assemblies (typically C /CLI). Purely managed assemblies (.NET 2.0) do not require this App.Config modification for compatibility with .NET 4.0.
The above is the detailed content of How Can I Reference a .NET 2.0 Mixed-Mode Assembly in a .NET 4.0 Project?. For more information, please follow other related articles on the PHP Chinese website!