在。net 4配置中,“useLegacyV2RuntimeActivationPolicy”做什么?

时间:2022-09-01 18:40:57

While converting a project that used SlimDX, and therefore has unmanaged code, to .NET 4.0 I ran into the following error:

在转换一个使用了SlimDX的项目,并因此有非托管代码的时候,我遇到了以下错误:

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.

混合模式组装是根据运行时版本“v2.0.50727”构建的,在4.0运行时不能加载,无需附加配置信息。

Googling around gave me the solution, which is to add this to the applications config:

google around给了我一个解决方案,就是把这个添加到应用程序配置中:

<configuration>
  <startup useLegacyV2RuntimeActivationPolicy="true">
    <supportedRuntime version="v4.0"/>
  </startup>
</configuration>

My question is, what is the useLegacyV2RuntimeActivationPolicy doing? I can't find any documentation about it.

我的问题是,useLegacyV2RuntimeActivationPolicy在做什么?我找不到任何有关它的文件。

2 个解决方案

#1


156  

After a bit of time (and more searching), I found this blog entry by Jomo Fisher.

经过一段时间(和更多的搜索),我找到了Jomo Fisher的博客条目。

One of the recent problems we’ve seen is that, because of the support for side-by-side runtimes, .NET 4.0 has changed the way that it binds to older mixed-mode assemblies. These assemblies are, for example, those that are compiled from C++\CLI. Currently available DirectX assemblies are mixed mode. If you see a message like this then you know you have run into the issue:

我们最近看到的一个问题是,由于对并行运行时的支持,. net 4.0改变了它与旧的混合模式程序集绑定的方式。例如,这些程序集是由c++ \CLI编译的。当前可用的DirectX程序集是混合模式。如果你看到这样的信息,你就知道你遇到了这个问题:

Mixed mode assembly is built against version 'v1.1.4322' of the runtime and cannot be loaded in the 4.0 runtime without additional configuration information.

混合模式组装是针对运行时版本“v1.1.4322”构建的,在4.0运行时不能加载,无需附加配置信息。

[Snip]

(剪)

The good news for applications is that you have the option of falling back to .NET 2.0 era binding for these assemblies by setting an app.config flag like so:

对于应用程序来说,好消息是您可以通过设置app.config标志,比如:

<startup useLegacyV2RuntimeActivationPolicy="true">
  <supportedRuntime version="v4.0"/>
</startup>

So it looks like the way the runtime loads mixed-mode assemblies has changed. I can't find any details about this change, or why it was done. But the useLegacyV2RuntimeActivationPolicy attribute reverts back to CLR 2.0 loading.

所以看起来运行时加载混合模式程序集的方式发生了变化。我找不到关于这个改变的任何细节,也找不到为什么要这么做。但是useLegacyV2RuntimeActivationPolicy属性返回到CLR 2.0加载。

#2


116  

Here's an explanation I wrote recently to help with the void of information on this attribute. http://www.marklio.com/marklio/PermaLink,guid,ecc34c3c-be44-4422-86b7-900900e451f9.aspx (Internet Archive Wayback Machine link)

下面是我最近写的一个解释,用于帮助解决关于这个属性的信息不足的问题。http://www.marklio.com/marklio/PermaLink,guid,ecc34c3c-be44-4422-86b7- 900e451f9.aspx (Internet Archive Wayback Machine link)

To quote the most relevant bits:

引用最相关的片段:

[Installing .NET] v4 is “non-impactful”. It should not change the behavior of existing components when installed.

v4“没有影响”。安装时不应改变现有组件的行为。

The useLegacyV2RuntimeActivationPolicy attribute basically lets you say, “I have some dependencies on the legacy shim APIs. Please make them work the way they used to with respect to the chosen runtime.”

useLegacyV2RuntimeActivationPolicy属性基本上允许您说,“我对遗留shim api有一些依赖”。请让他们按照他们过去选择的运行时的方式工作。

Why don’t we make this the default behavior? You might argue that this behavior is more compatible, and makes porting code from previous versions much easier. If you’ll recall, this can’t be the default behavior because it would make installation of v4 impactful, which can break existing apps installed on your machine.

我们为什么不把它作为默认行为呢?您可能会认为这种行为更加兼容,并且使得从以前版本移植代码更加容易。如果您还记得的话,这不是默认行为,因为它会使v4的安装变得有效,这会破坏您机器上安装的现有应用程序。

The full post explains this in more detail. At RTM, the MSDN docs on this should be better.

全文将更详细地解释这一点。在RTM,这方面的MSDN文档应该更好。

#1


156  

After a bit of time (and more searching), I found this blog entry by Jomo Fisher.

经过一段时间(和更多的搜索),我找到了Jomo Fisher的博客条目。

One of the recent problems we’ve seen is that, because of the support for side-by-side runtimes, .NET 4.0 has changed the way that it binds to older mixed-mode assemblies. These assemblies are, for example, those that are compiled from C++\CLI. Currently available DirectX assemblies are mixed mode. If you see a message like this then you know you have run into the issue:

我们最近看到的一个问题是,由于对并行运行时的支持,. net 4.0改变了它与旧的混合模式程序集绑定的方式。例如,这些程序集是由c++ \CLI编译的。当前可用的DirectX程序集是混合模式。如果你看到这样的信息,你就知道你遇到了这个问题:

Mixed mode assembly is built against version 'v1.1.4322' of the runtime and cannot be loaded in the 4.0 runtime without additional configuration information.

混合模式组装是针对运行时版本“v1.1.4322”构建的,在4.0运行时不能加载,无需附加配置信息。

[Snip]

(剪)

The good news for applications is that you have the option of falling back to .NET 2.0 era binding for these assemblies by setting an app.config flag like so:

对于应用程序来说,好消息是您可以通过设置app.config标志,比如:

<startup useLegacyV2RuntimeActivationPolicy="true">
  <supportedRuntime version="v4.0"/>
</startup>

So it looks like the way the runtime loads mixed-mode assemblies has changed. I can't find any details about this change, or why it was done. But the useLegacyV2RuntimeActivationPolicy attribute reverts back to CLR 2.0 loading.

所以看起来运行时加载混合模式程序集的方式发生了变化。我找不到关于这个改变的任何细节,也找不到为什么要这么做。但是useLegacyV2RuntimeActivationPolicy属性返回到CLR 2.0加载。

#2


116  

Here's an explanation I wrote recently to help with the void of information on this attribute. http://www.marklio.com/marklio/PermaLink,guid,ecc34c3c-be44-4422-86b7-900900e451f9.aspx (Internet Archive Wayback Machine link)

下面是我最近写的一个解释,用于帮助解决关于这个属性的信息不足的问题。http://www.marklio.com/marklio/PermaLink,guid,ecc34c3c-be44-4422-86b7- 900e451f9.aspx (Internet Archive Wayback Machine link)

To quote the most relevant bits:

引用最相关的片段:

[Installing .NET] v4 is “non-impactful”. It should not change the behavior of existing components when installed.

v4“没有影响”。安装时不应改变现有组件的行为。

The useLegacyV2RuntimeActivationPolicy attribute basically lets you say, “I have some dependencies on the legacy shim APIs. Please make them work the way they used to with respect to the chosen runtime.”

useLegacyV2RuntimeActivationPolicy属性基本上允许您说,“我对遗留shim api有一些依赖”。请让他们按照他们过去选择的运行时的方式工作。

Why don’t we make this the default behavior? You might argue that this behavior is more compatible, and makes porting code from previous versions much easier. If you’ll recall, this can’t be the default behavior because it would make installation of v4 impactful, which can break existing apps installed on your machine.

我们为什么不把它作为默认行为呢?您可能会认为这种行为更加兼容,并且使得从以前版本移植代码更加容易。如果您还记得的话,这不是默认行为,因为它会使v4的安装变得有效,这会破坏您机器上安装的现有应用程序。

The full post explains this in more detail. At RTM, the MSDN docs on this should be better.

全文将更详细地解释这一点。在RTM,这方面的MSDN文档应该更好。