gpt4 book ai didi

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

转载 作者:太空狗 更新时间:2023-10-30 01:06:07 25 4
gpt4 key购买 nike

我有一个用 .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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com