Supported runtime v4.0 in app.config after upgrading VS11 Beta to VS2012 RC

13,501

Solution 1

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.

Solution 2

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.

Share:
13,501

Related videos on Youtube

friend
Author by

friend

Updated on September 15, 2022

Comments

  • friend
    friend over 1 year

    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

  • friend
    friend over 11 years
    so when user has .NET 4.0 it will display error saying .NET 4.5 is required with that config. How about if that config is not there? Won't that also throw error anyway since I've targetted .NET 4.5?
  • user1703401
    user1703401 over 11 years
    Yes, but one that's a lot harder to interpret. Like MissingMethodException or FileNotFoundException, not a friendly message like "You don't have .NET 4.5, would you like me to install it for you?" See stackoverflow.com/a/10033128/17034
  • Matt Davis
    Matt Davis over 11 years
    @nobugz, I've always been a little confused as to which version of .NET I needed to make available alongside my application. Based on your comment above, am I to understand that applications targeting .NET 4.5 only have to make .NET 4.5 available? In other words, I don't have to worry if .NET 3.5, 3.0, etc. are on the system?
  • Leniel Maccaferri
    Leniel Maccaferri about 11 years
    You'll get a Configuration Error with this message: The 'targetFramework' attribute in the <compilation> element of the Web.config file is used only to target version 4.0 and later of the .NET Framework (for example, '<compilation targetFramework="4.0">'). The 'targetFramework' attribute currently references a version that is later than the installed version of the .NET Framework. Specify a valid target version of the .NET Framework, or install the required version of the .NET Framework.