简体   繁体   English

使用useLegacyV2RuntimeActivationPolicy和多个supportedRuntimes之间的区别是什么

[英]What's the difference between using useLegacyV2RuntimeActivationPolicy and multiple supportedRuntimes

What is the difference between the three following scenarios (in an app.config files of an exe)? 以下三种方案之间有什么区别(在exe的app.config文件中)?

<startup>
  <supportedRuntime version="v4.0" />
  <supportedRuntime version="v2.0" />
</startup>


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


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

I've read the MS documentation on it and some blogs but it still isn't very clear to me exactly what happens and when to use which. 我已经阅读了它上面的MS文档和一些博客但是我仍然不太清楚到底发生了什么以及何时使用它。

EDIT 编辑
I have a situation where a third party application was compiled with CLR 2 (and also uses legacy COM) and the allowed extensions that I've made for the application are compiled with CLR 4. So, recompiling the application is not an option for me. 我有一种情况,第三方应用程序使用CLR 2编译(并且还使用传统COM),我为应用程序所做的允许扩展是使用CLR 4编译的。因此,重新编译应用程序对我来说不是一个选项。 I just need to know the impact of the three scenarios. 我只需要知道三种情景的影响。

The useLegacyV2RuntimeActivationPolicy attribute is a bit of a cop-out. useLegacyV2RuntimeActivationPolicy属性有点像警察。 Setting it to true allows a .NET 4 program to load mixed-mode (C++/CLI) or [ComVisible] .NET assemblies that stated expressly in the registry that they need version 2.0.50727 of the runtime. 将其设置为true允许.NET 4程序加载混合模式(C ++ / CLI)或[ComVisible] .NET程序集,这些程序集在注册表中明确声明它们需要运行时版本2.0.50727。 It won't make any difference if you don't have such assemblies, they are fairly rare. 如果你没有这样的组件,它将没有任何区别,它们是相当罕见的。 The sane thing to do is to not use it, you'll get an error message when it is required. 理智的做法是不使用它,在需要时你会收到一条错误信息。 A FileLoadException whose message looks like: 一个FileLoadException,其消息如下所示:

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运行时加载。

The next sane thing to do is rebuild such assemblies to target .NET 4. Last thing you do is use that attribute. 下一个要做的事情就是重建这样的程序集来定位.NET 4.最后你要做的就是使用该属性。

If you offer more than one version of the CLR, like you did in the first two snippets, then you'll get the one that the EXE asks for in its manifest. 如果您提供多个版本的CLR,就像您在前两个片段中所做的那样,那么您将获得EXE在其清单中要求的那个版本。 The last one forces the v4 version. 最后一个强制 v4版本。 The implication is that you'll potentially run code that was only ever tested on CLR v2 on a different .NET runtime. 这意味着您可能会运行仅在不同.NET运行时上在CLR v2上测试过的代码。 This will almost always come to a good end, v4 is very compatible with v2. 这几乎总是会有一个好的结局,v4与v2非常兼容。 But they did take the opportunity to fix bugs in v4. 但他们确实借此机会修复了第4版中的错误。 You could be accidentally depend on buggy behavior. 你可能会意外地依赖有缺陷的行为。 Very rare of course. 当然非常罕见。

supportedRuntime specifies which runtime is used to actually run and execute the application itself. supportedRuntime指定用于实际运行和执行应用程序本身的运行时。 If you set this to v4.0 , then the 4.0 clr runtime will be used to start the application. 如果将其设置为v4.0 ,则将使用4.0 clr运行时来启动应用程序。 Adding v2.0 and v4.0 is saying that you'll allow the CLR 2 or 4 runtime to actually run the application. 添加v2.0v4.0表示您将允许CLR 2或4运行时实际运行该应用程序。

The useLegacyV2RuntimeActivationPolicy option changes the behavior when you load an assembly targeting the CLR 2 runtime from within an application executing in the CLR 4 runtime. 当从CLR 4运行时中执行的应用程序中加载面向CLR 2运行时的程序集时, useLegacyV2RuntimeActivationPolicy选项会更改行为。 When it is set to true , the 4.0 runtime will be used to load the CLR 2 assembly. 当它设置为true时,将使用4.0运行时加载CLR 2程序集。 This is mainly required if you're loading a mixed mode assembly targeting CLR 2 within a CLR 4 project, as you'll get an error otherwise. 如果您在CLR 4项目中加载针对CLR 2的混合模式程序集,则主要需要这样做,否则您将收到错误。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 在应用程序中使用“useLegacyV2RuntimeActivationPolicy”和supportedRuntime时出现问题 - Problem using ‘useLegacyV2RuntimeActivationPolicy’ & supportedRuntime in an application 启用useLegacyV2RuntimeActivationPolicy会产生什么影响? - Repercussions of enabling useLegacyV2RuntimeActivationPolicy? 'useLegacyV2RuntimeActivationPolicy'在.NET 4配置中做了什么? - What does 'useLegacyV2RuntimeActivationPolicy' do in the .NET 4 config? 在运行时设置.Net 4&#39;useLegacyV2RuntimeActivationPolicy&#39;? - Set .Net 4 'useLegacyV2RuntimeActivationPolicy' during runtime? .Net useLegacyV2RuntimeActivationPolicy在IIS 7.5中不起作用 - .Net useLegacyV2RuntimeActivationPolicy not working in IIS 7.5 如果配置文件不在安装文件夹中,则“ useLegacyV2RuntimeActivationPolicy”不起作用 - 'useLegacyV2RuntimeActivationPolicy' does not work if config file is not in installation folder 在VS 2010中为测试项目设置useLegacyV2RuntimeActivationPolicy - Setting useLegacyV2RuntimeActivationPolicy for test projects in VS 2010 Crystal Reports 和 .NET 4 - 无法加载文件或程序集(使用 useLegacyV2RuntimeActivationPolicy=“false”)crdb_adoplus.dll - Crystal Reports and .NET 4 - Could not load file or assembly (with useLegacyV2RuntimeActivationPolicy=“false”) crdb_adoplus.dll 我可以通过编程方式设置app.config&#39;useLegacyV2RuntimeActivationPolicy&#39;属性吗? - Can I set the app.config 'useLegacyV2RuntimeActivationPolicy' attribute programmatically? 通过文件关联启动应用程序时,未使用包含useLegacyV2RuntimeActivationPolicy的.NET app.config文件 - .NET app.config file containing useLegacyV2RuntimeActivationPolicy not being used when app launched via file association
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM