在同一过程中将.NET 3.5与4 / 4.5程序集混合 [英] Mixing .NET 3.5 with 4/4.5 assemblies in the same process

查看:173
本文介绍了在同一过程中将.NET 3.5与4 / 4.5程序集混合的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想将基于.NET 3.5 WinForms的应用程序迁移到最新的.NET版本(4.5)。

I'd like to migrate a .NET 3.5 WinForms based application to the latest .NET version (4.5).

该应用程序使用外部组件(可以

The application uses "external" components (can be thought of as plugins) that are also currently .NET 3.5 based.

我想知道在我们转换的情况下使用了哪些运行时/核心库。只有应用程序才能使用.NET 4.5进行编译?

I'd like to know what runtime/core libraries are used in case we convert ONLY THE APPLICATION to compile using .NET 4.5?

这种情况是否可以正常工作? (在4.5进程中加载​​.NET 3.5程序集)?
*插件程序集通过反射加载。

Should this scenario properly work? (loading .NET 3.5 assemblies in a 4.5 process)? * The plugin assemblies are loaded via reflection.

CLR运行时如何处理这种情况?这是安全的做法吗?

How does the CLR runtime handle such a scenario? is this a safe practice?

推荐答案

如果您将应用程序的主要EXE重新编译为目标.NET 4.x或使用带有< supportedRuntime> 元素的app.exe.config文件强制使用CLR版本4,那么使用.NET 3.5和.NET 4.0都不会遇到麻烦组件。 CLR v4可以轻松读取3.5程序集,它向后兼容。并非相反,CLR v2无法读取版本4程序集,这就是为什么如果EXE并非针对v4则需要.config文件的原因。

If you recompiled the main EXE of your app to target .NET 4.x or use an app.exe.config file with the <supportedRuntime> element to force CLR version 4 to get used then you'll have no trouble using both .NET 3.5 and .NET 4.0 assemblies. CLR v4 has no trouble reading 3.5 assemblies, it is backwards compatible. Not the other way around, CLR v2 can't read version 4 assemblies which is why you need the .config file if your EXE isn't targeting v4.

皱纹是3.5程序集对旧框架程序集的依赖。例如,它将要求mscorlib.dll的版本为2.0.0.0。 CLR自动翻译这些请求,并将其替换为4.0.0.0版本。一般而言,标准4.0框架程序集可以很好地与旧版本兼容。

The only wrinkle is the dependencies that your 3.5 assembly has on old framework assemblies. It will for example ask for version 2.0.0.0 of mscorlib.dll. The CLR automatically translates those requests and replaces them with version 4.0.0.0. Which in general works just fine, the standard 4.0 framework assemblies are very compatible with the old versions.

Microsoft确实抓住了机会,将4.0作为新的兼容版本,侧面版本和已修复的旧错误,这些错误很难避免不小心破坏依赖于错误行为的代码而冒犯的风险。它们是非常隐蔽的错误,这些错误修复几乎不可能使您陷入困境。但是,您必须重新测试代码以确保安全。

Microsoft did however take the opportunity with 4.0 being a new side-by-side version and fixed old bugs that could not be easily fixed without risking breaking code that accidentally relied on the buggy behavior. They are very obscure bugs and it is pretty unlikely these bug fixes will byte you. You do however have to re-test your code to make sure.

这篇关于在同一过程中将.NET 3.5与4 / 4.5程序集混合的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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