如何在 CLR 1.1 或 2.0 应用程序中使用 CLR 4.0 组件?

发布于 2024-09-28 20:13:02 字数 267 浏览 0 评论 0原文

虽然我看到过一些关于在较新的 CLR 4.0 应用程序中使用较旧的 CLR 2.0 组件的讨论,但如何处理相反的情况呢?

例如,如果一个人在 .Net 2.0 中有一个遗留应用程序,并且想要利用一种较新的业务逻辑,该业务逻辑充分利用了 4.0 版本的 CLR,那么人们将如何在遗留应用程序中引用较新的组件并访问它的方法?如果旧应用程序位于 .Net 1.1 中,同样的方法是否有效?

(为了清楚起见,附录)

虽然升级是理想的,但仍然存在边缘情况,这可能是技术或政治限制。

While I have seen some discussions on the utilization of an older CLR 2.0 component within a newer CLR 4.0 application, how would one handle the opposite case?

For example, if one had a legacy app in .Net 2.0, and wanted to take advantage of a newer business logic that took full advantage of the 4.0 version of the CLR, how would one go about referencing the newer component within the legacy application and accessing it's methods? And would the same method work if the legacy app was in .Net 1.1?

(Addendum For clarity)

While an upgrade is ideal, there still exist edge cases where this may be a technical or political limitation.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

空‖城人不在 2024-10-05 20:13:02

一般来说,您应该升级旧应用程序以使用 .NET 4。代码不应需要更改。

否则,处理此问题的主要受支持方法是通过 COM 互操作。您的 .NET 4 类可以标记为 [ComVisible],然后您可以构造互操作程序集以在旧的 .NET 版本中“使用”它。

然而,这有很多缺点——包括大量增加的复杂性和降低的性能。

In general, you should upgrade the legacy application to use .NET 4. The code should not require changes.

Otherwise, the main supported method to handle this is via COM interop. Your .NET 4 class can be marked [ComVisible], and then you can construct interop assemblies to "consume" it in older .NET versions.

This, however, has many disadvantages - including a lot of added complexity and reduced performance.

扭转时空 2024-10-05 20:13:02

您应该将较旧的 .Net 1.1 或 2.0 应用程序定位到 .Net 4.0 - 因为目标计算机无论如何都需要安装 .Net 4.0 才能使用 .Net 4.0 组件,因此将您的应用程序定位到 .Net 并没有真正的优势。网2.0。

You should target your older .Net 1.1 or 2.0 application at .Net 4.0 instead - as the target machine will need to have .Net 4.0 installed anyway in order to use the .Net 4.0 component there is no real advantage to targeting your application at .Net 2.0.

扮仙女 2024-10-05 20:13:02

查看 Rick Byers 和 Simon Hall:CLR 4 - 并排进行中 - 什么。如何。为什么。

检查评论:

假设我具有您在视频中提到的隔离级别,是否可以将 clr4 运行时进程内 SxS 加载到托管 clr2 应用程序(反之亦然)?如果是,我该怎么办?我必须调用他们的托管 API 吗?或者我是否需要来层或其他东西,然后为我加载其他 clr?他们有 beta1 的样本供我查看吗?


CLR 加载实际上是通过本机 API 发生的,可以直接使用托管 API(例如 ICLRMetaHost),也可以通过 COM 间接使用。您可以使用 .NET 的互操作工具在托管代码中执行此操作(无需实际编写任何本机代码)。所以是的,您可以编写在加载 CLR v4 的 CLR v2 中运行的代码,反之亦然。

我知道我们正在制作一些代码示例,但我认为它们还没有发布。请关注 CLR 团队博客的 SxS 类别。最简单的方法是使用一个版本的 .NET 构建托管 COM 组件,然后使用另一个版本的 .NET 中的 COM 互操作实例化它,就像没有 SxS 时一样。查找通过 .NET 2.0 构建和使用 COM 组件的任何示例。

我希望这有帮助,里克

Take a look to Rick Byers and Simon Hall: CLR 4 - Side-by-Side In-Process - What. How. Why.

Check this comment:

Assumed i have the level of isolation you mentioned in the video, is it possible to load to an managed clr2 application the clr4 runtime In-process SxS (and vice versa)? If yes, what do i have to do? Is their any managed api i have to call? Or do i need the come layer or something which then loads the other clr for me? Are their any samples for the beta1 where i can have a look at?


CLR loading is really something that happens through native APIs, either using hosting APIs directly (eg. ICLRMetaHost), or indirectly via COM. You can do this in managed code (no need to actually write any native code) by using .NET's interop facilities. So yes, you could write code that ran in CLR v2 which loaded CLR v4 and vice-versa.

I know we've got some code samples in the works, but I don't think they've been posted yet. Keep an eye on the SxS category of the CLR team blog. The simplest way is to build a managed COM component using one version of .NET, and then instantiate it using COM-interop from another version of .NET exactly as you would without SxS. Look for any samples for building and using COM components with .NET 2.0.

I hope this helps, Rick

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文