3

Suppose I have a WinForms app that is built and compiled against .NET 2.0 using VS2008.

It is my understanding that at runtime, the app will attempt to load the .NET 2.0 CLR first, (because that is what it was compiled against), regardless of anything that may be listed in any "supportedRuntime" element of the app.config file.

If it can't find it, then it will then go through a process of deciding on another version by checking the app.config, etc.

For example, if .NET 2/3/3.5 and .NET 4.0 are installed on a machine, and I have:

<supportedRuntime>V4.0</supportedRuntime>

in the app.config, the app will still choose to load and run .NET 2.0.

Is that correct?

Thanks.

1 Answer 1

9

The MSDN page seems to be clear that the one used to build is only the fallback case:

http://msdn.microsoft.com/en-us/library/w4atty68.aspx

If the <supportedRuntime> element is not present in the application configuration file, the version of the runtime used to build the application is used.

Are you seeing behavior that doesn't match that of this MSDN page?

4
  • btw, just as a data point, I used supportedRuntime to force my powershell process to load under 4.0 when I needed some 4.0 assemblies to get loaded and it worked just fine for me. Jun 3, 2010 at 7:29
  • 1
    Hmmm, this link msdn.microsoft.com/en-us/library/9w519wzk.aspx would seem to suggest that the first thing that happens is to check what the app is built against first and use that CLR if it is present.
    – Andy
    Jun 3, 2010 at 17:19
  • 4
    Good point - IMHO that's a doc bug based on the former page. Besides my PowerShell experience in the past (PS v2 seems to have a problem with it), it's also simple to test by creating a new console app targeting 2.0 (I did this in VS 2010) with just 1 line of Console.WriteLine("CLR version: {0}", Environment.Version); - without an exe.config in place (by default), and running the built exe from the command line, I get: CLR version: 2.0.50727.4927 (which is what we would expect). If I add a config with supported of v4.0 (just via notepad, no VS action) I get CLR version: 4.0.30319.1 Jun 4, 2010 at 16:05
  • 1
    How to: Configure an App to Support .NET Framework 4 or 4.5 msdn.microsoft.com/en-us/library/jj152935.aspx "The configuration file reads <supportedRuntime> entries in the order they are listed, and uses the first .NET Framework version listed" HOWEVER "However, .NET Framework 1.0, 1.1, 2.0, 3.0, and 3.5 apps do not automatically run on the .NET Framework 4 or later, and in some cases, the user may receive an error and may be prompted to install the .NET Framework 3.5. The activation behavior may also depend on the user’s operating system"
    – Booji Boy
    Feb 4, 2015 at 15:02

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.