什么额外的配置“是必要引用一个.NET 2.0混合模式程序集在.NET 4.0的项目?必要、模式、程序、项目

2023-09-02 10:14:53 作者:我这个名字有九个字

我有一个在我想使用一些.NET 4.0的功能,但一个核心要求的项目,我可以用它编译的2.x中System.Data.SQLite框架我看到提到这一点是可能的,如the这里接受的答案,但我不知道如何真正做到这一点。

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.

当我只是尝试和运行我4.0的项目,而引用2.X组装我得到:

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

混合模式组件构建针对运行时的版本V2.0.50727   并且不能在4.0运行时加载而无需额外   配置信息。的

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?

推荐答案

为了使用CLR 2.0的混合模式组装的,你需要修改app.config文件包括:

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

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

关键是 useLegacyV2RuntimeActivati​​onPolicy 标志。这将导致使用最新的版本(4.0)来加载混合模式程序集的CLR。没有这一点,它不会工作。

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.

请注意,对于混合模式(C ++ / CLI)组件此有关的事项。您可以加载所有被管理的CLR 2装配体,而在的app.config 指定此。

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.