简体   繁体   中英

Assembly compiled in older .NET version running in newer .NET version, will behavior change?

I have an assembly that is compiled with .NET 3.5. I cannot recompile it in .NET 4.5 since it is used in other applications that are still running .NET 3.5. When I use the assembly in my apps that are running .NET 4.5 will the assembly be treated as if it is running in .NET 4.5 instead of .NET 3.5? I have a WinForms app and a WebForms app both in .NET 4.5. If there are changes in behavior between .NET 3.5 and .NET 4.5, with the assembly return the 4.5 results?

Usually .Net frameworks are backward-compatible, so executing an assembly developed in .Net 3.5 shouldn't be a problem on 4.5.

You should see: 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.

But there could be problems as well like the one mentioned in the article :

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.

The best way for you would be make sure your test cases pass after including dll from 3.5.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM