使用在旧版.NET Framework中编译的程序集是否会影响整体性能? [英] Does using assembly compiled in older version of .NET framework affects whole performance?

查看:106
本文介绍了使用在旧版.NET Framework中编译的程序集是否会影响整体性能?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

让我们想象我们有两个程序集:

Lets imagine that we have two assemblies:


  1. Foo.Logic(在.NET 2.0框架上编译)

  2. Foo.Application(在.NET 4.0框架上编译),具有引用并使用已编译的Foo.Logic。

推荐答案

在您描述的问题中,一切都会正常进行。

In the situation you described in the question, everything will Just Work™ without any problems.

.NET 4.0应用程序会将.NET 2.0库直接加载到.NET 4.0运行时环境中。除非您明确要求,否则它将不使用并行执行。网上有很多关于此的错误信息或不清楚的陈述,因此请谨慎评估您的阅读内容。

A .NET 4.0 application will load a .NET 2.0 library directly into the .NET 4.0 runtime environment. It will not use side-by-side execution unless you explicitly ask it to. There's a lot of misinformation or unclear statements made about this around the web, so be careful in evaluating what you read.

我终于遇到了本文,该文章证实了乔恩·斯凯特(Jon Skeet)的回答。特别是,该文章解释了(强调):

I finally came across this article, which confirms what Jon Skeet says in his answer. In particular, the article explains (emphasis added):


In-Proc SxS不能解决库开发人员面临的兼容性问题。 任何由应用程序直接加载的库(通过直接引用或Assembly.Load)将继续直接加载到运行时,并由应用程序的AppDomain加载。这意味着,如果将应用程序重新编译为针对.NET Framework 4运行时运行,并且仍然具有针对.NET 2.0构建的从属程序集,则这些从属程序也将在.NET 4运行时上加载。因此,我们仍然建议针对您希望支持的框架的所有版本测试您的库。这就是我们继续保持高水平向后兼容性的原因之一。

In-Proc SxS does not solve the compatibility problems faced by library developers. Any libraries directly loaded by an application--either via a direct reference or an Assembly.Load--will continue to load directly into the runtime and AppDomain of the application loading it. This means that if an application is recompiled to run against the .NET Framework 4 runtime and still has dependent assemblies built against .NET 2.0, those dependents will load on the .NET 4 runtime as well. Therefore, we still recommend testing your libraries against all version[s] of the framework you wish to support. This is one of the reasons we have continued to maintain our high level of backward compatibility.

但是如果您对更多感兴趣,关于具体细节,值得一提的是,CLR 4.0版引入的新功能之一是能够在单个过程中同时运行多个版本的运行时。这称为在并行执行过程中 (或 Inproc SxS(如果您非常酷)),并且是非常强大的工具。您可以阅读有关它的更多信息在CLR团队博客上

But if you're interested in even more of the nitty-gritty details, it's worth mentioning that one of the new features introduced with version 4.0 of the CLR is the ability to run multiple versions of the runtime at the same time from in a single process. This is called "In Process Side-by-Side Execution" (or "Inproc SxS" if you're very cool), and is a very powerful tool. You can read more about it here on the CLR team's blog.

这里有一些漂亮的图片用于演示:

Here are some pretty pictures for demonstration purposes:

请注意蛋糕用于在.NET 2.0之上构建.NET 3.0和3.5版本的模型。这意味着它们将并排运行而不会出现任何问题。但是隔离其他版本 会造成问题。

Note the "layer-cake" model that was used to build the .NET 3.0 and 3.5 releases on top of .NET 2.0. That means that they'll all run side-by-side without any problems. But the isolation of the other versions will create a problem.

但是,如上所述,.NET 4.0通过Side-by解决了此问题。 -侧面执行:

However, as mentioned above, .NET 4.0 solves this problem with Side-by-Side Execution:

当然,这主要适用于涉及COM并与Outlook等外部应用程序互操作的情况,但这仍然是一个非常酷的功能。

Of course, this is mostly applicable to situations involving COM and interop with external applications like Outlook, but it's still a very cool feature.

但是无论哪种方式,您都不会看到这种方法的任何问题,无论是兼容性,性能还是其他方面。

But either way, you shouldn't see any problems whatsoever with this approach, either with compatibility, performance, or whatever else.

这篇关于使用在旧版.NET Framework中编译的程序集是否会影响整体性能?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆