如何在 CLR 1.1 或 2.0 应用程序中使用 CLR 4.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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
一般来说,您应该升级旧应用程序以使用 .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.
您应该将较旧的 .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.
查看 Rick Byers 和 Simon Hall:CLR 4 - 并排进行中 - 什么。如何。为什么。
检查此评论:
Take a look to Rick Byers and Simon Hall: CLR 4 - Side-by-Side In-Process - What. How. Why.
Check this comment: