Question

After upgrading from VS11 Beta to VS2012 RC - I've modified from targeting .NET 4.0 to .NET 4.5. I notice in app.config following section

<startup>
    <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" />
</startup>

What is the above for?

When I tried to create a new project (not upgrade of existing project) from within VS2012 RC I don't see the above section in app.config

Was it helpful?

Solution

That's a side-effect of the eternal .NET versioning quagmire. .NET 4.5 is not a side-by-side version of the .NET framework, it completely replaces a .NET 4.0 install. Much like 3.0 and 3.5 replaced a .NET 2.0 install.

The 3.0 and 3.5 updates were pretty mild, the framework just acquired a bunch of new assemblies. The CLR and the core base class assemblies didn't change. Much.

The clr.dll file included with the 4.5 version of the framework still has the 4.0.30319 version number. The same version number of the 4.0 version of the CLR. And has no trouble executing .NET apps that target the .NET 4.0 framework.

That framework version however was heavily modified internally. It acquired the language projection that enables writing Metro apps that run on Windows 8 in a managed language. Heavy changes include moving classes from one assembly to another, allowing the deploy on a phone or slate to be modest. The app.exe.config file added to your project ensures that your user has that required version. Deploying the .config file is optional, but the user will see a pretty opaque exception message when he only has .NET 4.0 installed. Not actually sure what that looks like. The automatic install that's triggered when he doesn't have 4.5 probably also doesn't work.

OTHER TIPS

While Hans Passant is correct in everything he says he misses a key point which is the role of the PE header in this debacle.

Because Dotnet 4.5 is an in-place install over the top of Dotnet 4.0, and because it doesn't update the Dotnet version number, the result is that binaries built using Dotnet 4.5 have the old Dotnet 4.0 version number in their binary's PE header (4.0.30319).

Because the CLR uses this value in the PE header to determine which version of the Dotnet Framework to load, and because this value doesn't change for assemblies built against Dotnet 4.5, then in the absence of any additional information the CLR has no way of knowing whether an assembly with 4.0.30319 in the PE header requires linking to Dotnet 4.0 or 4.5.

It's the presence of the supportedRuntime element in app.config that provides this extra information to the CLR. So if you launch a Dotnet 4.5 application with the supportedRuntime entry present on a system that only has Dotnet 4.0 installed, then the CLR will pop up a helpful message informing you that you don't have the required version of Dotnet installed. Whereas if you launch the same Dotnet 4.5 application without the supportedRuntime entry on a system that only has Dotnet 4.0 installed, then the application may start to run, but then crash when it later tries to use a Dotnet 4.5 feature.

While projects built using VS2012 RC and targeting Dotnet 4.5 might have had the supportedRuntime entry missing, projects built using VS2012 RTM do have the entry.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top