3
votes

If .NET application(Form/Web) is built with Framework 2.0, will it work with a computer having only version 4.0 of the framework?

For example I installed a fresh copy of Win Server 2003 and updated the system with v4.0 of the .NET framework(then system had only 1.0, 1.1 and 4.0 of .NET) but when installing SQL Server 2008 R2 Express the setup asked to install yet another v3.5 SP1 of the framework.

2

2 Answers

5
votes

Yes your 2.0 application will work on the computer which has 4.0 framework. Backward compatibility is there in dot net 4.0.

For more information have a look at this msdn article

MSDN says

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.

However you need to target the supportedruntime to 4.0 in your 2.0 application configuration file.

4
votes

You need to add an entry to the app.config to opt-in to running on CLRv4.

<configuration>
    <startup>
        <supportedRuntime version="v2.0.50727"  />
        <supportedRuntime version="v4.0"  />
    </startup>
</configuration>

(If you don't add the v2 info it will only run on the v4 CLR!)