Troubleshooting Mixed-Mode .NET 2.0 Assemblies in .NET 4.0 Projects
Referencing a mixed-mode .NET 2.0 assembly within a .NET 4.0 project can lead to the error: "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." This guide details the necessary configuration steps.
To successfully load the assembly, you must configure your application:
Adjust the App.config
File:
Insert the following XML snippet into your project's App.config
file:
<code class="language-xml"><?xml version="1.0"?> <configuration> <startup useLegacyV2RuntimeActivationPolicy="true"> <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0" /> </startup> </configuration></code>
Understanding the Key Setting:
The crucial setting is useLegacyV2RuntimeActivationPolicy="true"
. This directive compels the Common Language Runtime (CLR) to utilize the latest version (4.0) for loading the mixed-mode assembly. Omitting this will result in a load failure.
Important Consideration: This configuration is exclusively for mixed-mode (C /CLI) assemblies. Purely managed .NET 2.0 assemblies do not require this App.config
modification.
The above is the detailed content of How to Resolve 'Mixed mode assembly is built against version 'v2.0.50727'' Errors When Referencing .NET 2.0 Assemblies in a .NET 4.0 Project?. For more information, please follow other related articles on the PHP Chinese website!