none
App config file - Different .net versions RRS feed

  • Question

  • Hi Together.

    I have a question concerning differnet .net versions compatibility.

    I compiled my application with .net 4.5 and configured app config as follows.

    <?xml version="1.0" encoding="utf-8"?>
    <configuration>
        <startup useLegacyV2RuntimeActivationPolicy="true"> 
          <supportedRuntime version="v4.0"/>
          <supportedRuntime version="v2.0.50727"/>
        </startup>
        
    </configuration>

    If i run the app on the Computers which has .net 4. it is working.

    But if i run it on Computers with .net 3.5 i get error messge that i need to install 4.xxx Version.

    What am i doing wrong and is it possible to make application compatible for differen .net versions without compiling it in differen

    .net versions?

    Thanks in advance for your answer.

    Tuesday, September 18, 2018 12:26 PM

Answers

  • Yes, you'll have to multi-compile if you want to be able to write newer (v4) code while still supporting .NET 3.x. You cannot use the newer features on .NET 3.x. Separate builds will allow you to evolve the current code base without having to deal with legacy concerns.

    Server 2008 is EOL in 2020 so this should be a temporary solution anyway. Note that Server 2008 SP2 supports .NET through .NET 4.6 so ideally just have your clients upgrade (if they haven't already) and then you are back to a single compilation.


    Michael Taylor http://www.michaeltaylorp3.net

    Tuesday, September 18, 2018 3:40 PM
    Moderator

All replies

  • The useLegacyV2RuntimeActivationPolicy simply adjusts the behavior of loading pre-v4 assemblies into a v4 host. With it set to true they will continue using the CLR v2 so you'll have 2 hosts running. This is going to cause problems in some cases because they are separate CLR instances.

    The supportedRuntime attributes allow you to specify what version(s) of the runtime you want to support. To be honest I don't know that I've seen anyone use this since the early v2 days. Ultimately your code won't be able to use any v4 features if you want to target v2. It doesn't automagically allow your .NET v4 app to run against an older framework as there are components that simply aren't there. The primary purpose of this was (originally) to allow you to opt into newer framework versions. If your app is targeting v4 at compilation then that version of the runtime is what you're going to need.

    At this point it is always important to bring up the support cycle of the .NET Framework. You shouldn't be supporting versions that MS doesn't support anymore. Having said that, if you need a v4 version of your app that can use the newer features but still run on v2 then you have little choice but to create 2 binaries. The v2 binary can only use features available through .NET 3.5. This means things like tasks and spans and things along those lines won't work. You'll have to write code that is equivalent. You can continue to use a single code base via #if statements if needed but you'll have to compile to multiple targets. The newer SDK project format (if you can use it) supports multi-targeting but otherwise your best bet is a separate project and use links to the main code base.

    Another alternative is to simply build a "final" version of your v2 code and ensure it is branched in your source control system. Then your "current" version of the code is always v4. The only time you'd want to go back to the v2 version is for hotfixes which ideally should be rare. This allows you to continue development with the new features without the baggage of #if and multi-compilation.


    Michael Taylor http://www.michaeltaylorp3.net

    Tuesday, September 18, 2018 2:43 PM
    Moderator
  • Hi Michael

    Thanks for your answer.

    The problem is that i have mixed Enviroment and some Windows 2008 Server which has only 3.5 on defult base and my application has to run on those server too and i was opinion that if i configure app config file that it will take automatically .net Version which is installed on local Maschine.I use in my application the classes and functions  which are available in .net 3.5 .

    In that case i have to compile with different .net Versions.


    • Edited by todomati Tuesday, September 18, 2018 3:34 PM
    Tuesday, September 18, 2018 3:31 PM
  • Yes, you'll have to multi-compile if you want to be able to write newer (v4) code while still supporting .NET 3.x. You cannot use the newer features on .NET 3.x. Separate builds will allow you to evolve the current code base without having to deal with legacy concerns.

    Server 2008 is EOL in 2020 so this should be a temporary solution anyway. Note that Server 2008 SP2 supports .NET through .NET 4.6 so ideally just have your clients upgrade (if they haven't already) and then you are back to a single compilation.


    Michael Taylor http://www.michaeltaylorp3.net

    Tuesday, September 18, 2018 3:40 PM
    Moderator