Backwards Compatibility of .NET Framework 4 Backwards Compatibility of .NET Framework 4 wpf wpf

Backwards Compatibility of .NET Framework 4


.Net 3.5/2.0 Applications do not automatically run on the .Net 4.0 runtime. You have to specify explicitly for your application that it should run on .Net 4.0 in your App.config by adding:

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

In case you have third party components you also have to mark them as being ready for 4.0:

<configuration>   ...   <runtime>      ...      <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">         ...         <dependentAssembly>            <assemblyIdentity name="AssemblyName" publicKeyToken="31bf3856ad364e35"/>            <bindingRedirect oldVersion="3.5.0.0-3.5.0.0" newVersion="4.0.0.0"/>         </dependentAssembly>         ...      </assemblyBinding>      ...   </runtime>   ...</configuration>


the different version run side by side, so yes they need to install 3.5 even if they have already installed 4.0. But they will not interfere with each other, so your program will continue to use 3.5 unless you recompile it to target 4.0 (or configure it to use 4.0 - see edit below).

As was pointed out in this question microsoft has some guidance on this:

The .NET Framework 4 is highly compatible with applications that are built with earlier .NET Framework versions, except for some changes that were made to improve security, standards compliance, correctness, reliability, and performance.

The .NET Framework 4 does not automatically use its version of the common language runtime to run applications that are built with earlier versions of the .NET Framework. To run older applications with .NET Framework 4, you must compile your application with the target .NET Framework version specified in the properties for your project in Visual Studio, or you can specify the supported runtime with the <supportedRuntime> Element in an application configuration file.

You can install .NET 3.5 and .NET 4.0 along side each other. Visual Studio 2010 also includes improved targetting support for .NET 3.5. ScottGu's blog talks about this in more detail.

EDIT:As has been pointed out, you could modify the config of your app to tell it to use the 4.0 runtime if you want. this may or may not be ok depending on the bits of the framework you app uses. Safest it to install 3.5, but it is not strictly necessary, although you do have to make a change to your config to get it to work.


Thank you all, and thank you Foxfire, your method works.

And there is one tricky thing that I would like to share is the order of nodes.

When I set it like this below, it works both for 3.5 and 4.0.

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

And if I change the order, the APP will crash on the OS has only 4.0 installed.

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