19

We have an WPF Application build on .net framework 3.5.

Some testers find if they uninstall .net framework 3.5, but install .net framework 4.0, our APP fails to launch itself.

Dose this mean that .net framework 4.0 does not include all 3.5 libs, and users have to install .net 3.5 even though they have 4.0?

I see here are some migration issues listed by Microsoft http://msdn.microsoft.com/en-us/library/ee941656.aspx#windows_presentation_foundation_wpf

Are they all breaking changes so that the backward compatibility is ruined?

Thanks

1

3 Answers 3

20

.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>
3
  • did you mean 'You have to specify explicitly for your application that it should run on .Net 4.0 in your App.config'?
    – Sam Holder
    Commented May 12, 2010 at 8:09
  • 5
    I seriously doubt the <bindingRedirect> is appropriate. These 3rd party assemblies will have their own [AssemblyVersion], it will match the .NET version only by accident. <supportedRuntime> is enough to convince mscoree.dll to load the 4.0 CLR. Commented May 12, 2010 at 11:33
  • Actually a .NET 2.0 library can be loaded in a .NET 4 application, what I found more tricky is that they changed some subtle details about AppDomain.AssemblyLoad e AppDomain.AssemblyResolve. Commented May 18, 2012 at 13:51
9

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.

5
  • Why does running side-by-side mean that they need to install 3.5?
    – Gabe
    Commented May 12, 2010 at 8:05
  • 1
    yes, if your app is built against 3.5, they need to have 3.5 installed. installing 4.0 will not install 3.5, and your program will not automatically use 4.0 if 3.5 is not installed.
    – Sam Holder
    Commented May 12, 2010 at 8:09
  • So can't he just use the <supportedRuntime> element in his config and then not need to have 3.5 installed?
    – Gabe
    Commented May 12, 2010 at 8:11
  • That depends on whether the application actually will run under 4.0, there are breaking changes in some places, so the safest best is to have them install 3.5. Commented May 12, 2010 at 8:14
  • sorry Gabe, I misread your first comment (thought there was supposed to be a comma after the Why). As has been pointed out he could use a binding redirect to make his app run on 4.0 rather than 3.5, but he would have to be wary of the breaking changes. My point was that is does not happen automatically.
    – Sam Holder
    Commented May 12, 2010 at 8:19
7

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>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.