31

In the past not every new version of .NET came with a new version of the CLR. I know .NET 1.0, 1.1, 2.0 and 4.0 did, but .NET 3.0 and 3.5 did not.

Will .NET 4.5 introduce a new CLR? And how does one tell if there's a new CLR?

BoltClock
  • 700,868
  • 160
  • 1,392
  • 1,356
Michiel van Oosterhout
  • 22,839
  • 15
  • 90
  • 132

7 Answers7

27

Yes, .NET 4.5 has a brand spanking new version of the CLR, you can read about the improvements at;

http://blogs.microsoft.co.il/blogs/sasha/archive/2011/09/17/improvements-in-the-clr-core-in-net-framework-4-5.aspx

To clarify; this is a new version of the CLR that actually replaces the 4.0 one, so whether to call it an update or a new CLR is disputable.

To tell which CLR version you're running under, use

System.Runtime.InteropServices.RuntimeEnvironment.GetSystemVersion()
Joachim Isaksson
  • 176,943
  • 25
  • 281
  • 294
  • 3
    What do you mean by 'new'? In a sense every change to the CLR can be seen as 'a new CLR'. However, .NET 4.5 is certainly not a side-by-side release. It will replace .NET 4.0. In that sense Hans Passant's answer is correct. – Steven Jan 10 '12 at 21:16
  • Yes, I guess you could see it both ways, 4.5 requires an upgraded CLR, if you see it as new or not is a matter of discussion. – Joachim Isaksson Jan 10 '12 at 21:19
  • The question is ambiguous. That's why both your and Hans’s answer are correct, while you say the exact opposite :-) – Steven Jan 10 '12 at 21:44
  • @Steven : it's not that ambiguous. The OP clearly understood what happened in .NET 3.0 and 3.5. An important insight, it will happen again at 4.5 – Hans Passant Jan 11 '12 at 00:22
  • My question is somewhat ambiguous, in the title is 'a new version', in the question is 'a new CLR'. For now I'll accept this answer because if clr.dll is newer after installing .NET 4.5 then I consider that a 'new CLR'. That Microsoft choses to not version it that way seems strange to me, but then I don't know exactly why they do that. – Michiel van Oosterhout Jan 11 '12 at 07:47
  • Read [Scott Hanselman's April 2, 2012 blog post](http://www.hanselman.com/blog/NETVersioningAndMultiTargetingNET45IsAnInplaceUpgradeToNET40.aspx) for clarification. – Lee Grissom Jun 02 '12 at 02:09
  • 2
    The method you quote gives only the three first components, major.minor.build. That will always be `4.0.30319` for both .NET 4, .NET 4.5, and .NET 4.5.1. If you need all four components, major.minor.build.revision, use **`System.Environment.Version`** property instead. The revision number is changed with hotfixes and new versions of the framework. – Jeppe Stig Nielsen Oct 29 '13 at 14:16
  • 1
    http://msdn.microsoft.com/en-us/library/bb822049(v=vs.110).aspx - Features and IDE section, it's not a new CLR! – Peter Kiss Nov 07 '13 at 13:43
  • This answer is not correct. According to Microsoft the .NET Framework 4.5 uses CLR 4. Please check the table in this link [.Net Version and Dependencies](https://learn.microsoft.com/en-us/dotnet/framework/migration-guide/versions-and-dependencies?redirectedfrom=MSDN). – Marlon Assef Feb 10 '20 at 22:42
17

No, it is still version 4.0.30319. The new revision of clr.dll and friends will replace the existing ones on your machine. Same scheme as used in .NET 3.0, 3.5 and 3.5SP1. Checking to see if 4.5 is installed requires the same approach as those versions, you check the registry.

Community
  • 1
  • 1
Hans Passant
  • 922,412
  • 146
  • 1,693
  • 2,536
14

Yes. The version of the CLR changes from 4.0.30319.269 to 4.0.30319.17379. So, the CLR is new, but it is backwards-compatible with the .NET 4.0 CLR. You shouldn't need to re-compile any code written for and compiled by .NET v4.0.

From the .NET Framework Versions and Dependencies page on MSDN:

The .NET Framework 4.5 RC is an in-place update that replaces the .NET Framework 4 on your computer. After you install this update, your .NET Framework 4 apps should continue to run without requiring recompilation. However, some changes in the .NET Framework may require changes to your app code.

Additionally, from the .NET Framework blog:

.NET Framework 4.5 is an in-place update that replaces .NET Framework 4 (rather than a side-by-side installation). Our goal is for .NET 4.5 to be fully backward compatible with applications built for .NET 4

There are some changes that are not backwards compatible. See the Application Compatibility in the .NET Framework 4.5 RC page on MSDN.

Official guidance from Microsoft, and good coding practice, is not to detect specific versions of the CLR. Rather, you should detect if certain features are present. Instead of

public static bool IsDotNet45()
{
    return Environment.Version.Major == 4 &&
           Environment.Version.Revision > 17000;
}

do something like:

public static bool SupportsReflectionContext()
{
    // Class "ReflectionContext" exists from .NET 4.5 onwards.
    return Type.GetType("System.Reflection.ReflectionContext", false) != null;
}
Aaron Jensen
  • 25,861
  • 15
  • 82
  • 91
2

Although I doubt that this was available in it's current format at the time of the question, here is the CLR Guide on MSDN where it shows all of the Framework versions and the CLR version that they include. I found it very helpful, so I thought I would share.

Next to .NET 4.5 it states that it includes CLR 4.

Derek W
  • 9,708
  • 5
  • 58
  • 67
1

.NET 4 and .NET 4.5 (including 4.5.1 and 4.5.2) are on the CLR version 4.0

More detail: https://msdn.microsoft.com/en-us/library/8bs2ecf4(v=vs.110).aspx

Timeless
  • 7,338
  • 9
  • 60
  • 94
VnDevil
  • 1,321
  • 15
  • 13
0

.NET Framework 4.5 is like a service pack to .NET Framework 4 with some additional features.

Andrew Barber
  • 39,603
  • 20
  • 94
  • 123
Varun
  • 284
  • 3
  • 4
  • 1
    That seems a slightly odd way to describe it. I guess it's true in some ways as an analogy, but I dunno if it really answers the question: is there a new CLR. – Andrew Barber Oct 16 '12 at 16:12
  • I see no problem with this comment. CLR 4.5 actually replaces CLR 4 so it should be considered and update. – Yogee Dec 13 '13 at 11:54
0

Scott Hanselman has a post on his blog addressing this question. You can find out about it here:

http://www.hanselman.com/blog/NETVersioningAndMultiTargetingNET45IsAnInplaceUpgradeToNET40.aspx

The short of it is that there are updates to the CLR that improve performance and added new libraries. The CLR used by .NET 4.5 is compatible with .NET 4. It's considered to be a minor update. These minor updates are what Microsoft calls an in-place update.

CoderBBB
  • 11
  • 1
  • 1