c# - 在较新的 .NET 版本中运行的旧 .NET 版本中编译的程序集,行为会改变吗?

标签 c# asp.net .net winforms .net-4.5

我有一个用 .NET 3.5 编译的程序集。我无法在 .NET 4.5 中重新编译它,因为它用于仍在运行 .NET 3.5 的其他应用程序中。当我在运行 .NET 4.5 的应用程序中使用该程序集时,该程序集是否会被视为在 .NET 4.5 而不是 .NET 3.5 中运行?我在 .NET 4.5 中有一个 WinForms 应用程序和一个 WebForms 应用程序。如果 .NET 3.5 和 .NET 4.5 之间的行为发生变化,程序集会返回 4.5 结果吗?

最佳答案

通常 .Net 框架是向后兼容的,因此执行在 .Net 3.5 中开发的程序集在 4.5 上应该不是问题。

您应该看到:Version Compatibility in the .NET Framework

The .NET Framework 4.5 is backward-compatible with applications that were built with the .NET Framework versions 1.1, 2.0, 3.0, 3.5, and 4. In other words, applications and components built with previous versions of the .NET Framework will work on the .NET Framework 4.5.

但也可能会出现文章中提到的问题:

However, in practice, this compatibility can be broken by seemingly inconsequential changes in the .NET Framework and changes in programming techniques. For example, performance improvements in the .NET Framework 4 can expose a race condition that did not occur on earlier versions. Similarly, using a hard-coded path to .NET Framework assemblies, performing an equality comparison with a particular version of the .NET Framework, and getting the value of a private field by using reflection are not backward-compatible practices. In addition, each version of the .NET Framework includes bug fixes and security-related changes that can affect the compatibility of some applications and components.

对您而言,最好的方法是确保您的测试用例在包含 3.5 的 dll 后通过。

关于c# - 在较新的 .NET 版本中运行的旧 .NET 版本中编译的程序集,行为会改变吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16376023/

相关文章:

c# - 无法以与 C# 相同的格式为 WCF 服务传递 java 参数

c# - 如何动态更改 WPF 中 GridView 列的顺序?

javascript - 从数据库加载时网页挂起,并且大数据未显示在 asp.net mvc5 的图表上

.net - 在 Visual Studio 设计器中公开枚举(标志)集合

c# - 新实例的泛型类型实现了什么?

c# - 在一对多 Entity Framework 关系中使用 Dynamic LINQ Where

asp.net - Lucene.net多字段搜索

c# - 使动态创建的 Excel 报告可下载

c# - 在 .NET 中比较两种 RGB 颜色的最快方法是什么?

c# - 对 TcpClient.ConnectAsync 方法的取消支持