views:

285

answers:

1

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.

+2  A: 

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?

James Manning
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.
James Manning
Hmmm, this link http://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
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
James Manning
Thanks James, nice clarification.
Andy