When executing an application on .net 4.0, compiled under .net 2.0

Viewed 7275

Assuming that:

  1. The C# source code below is compiled under .NET 2.0 (CLR 2.0); and
  2. The above application uses the app.config listed below; and
  3. Only .NET 4.0 (CLR 4.0) is installed on the environment of the client executing the application,

then which version of .NET is internally loaded to execute the application on the client's environment?

Description

The console application below will simply show that its CLR version is v4.0.30319 in the console, but @Reed Copsey's answer of the stack (CLR 2.0 vs 4.0 performance?) shows that .NET 2.0 is loaded in this case. Moreover, at MSDN it says when useLegacyV2RuntimeActivationPolicy is set to false false:

Use the default activation policy for the .NET Framework 4 and later, which is to allow legacy runtime activation techniques to load CLR version 1.1 or 2.0 into the process.

It sounds like .NET 2.0 is loaded in spite of the app.config having a .NET 4.0 configuration. Have I misunderstood anything?

Source

C# source code

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            string version = Environment.Version.ToString();
            Console.WriteLine(version);
        }
    }
}

app.config

<?xml version="1.0"?>
<configuration>
    <startup useLegacyV2RuntimeActivationPolicy="false">
        <supportedRuntime version="v4.0.30319"/>
    </startup>
</configuration>
1 Answers
Related