4

I am trying to use the microsoft reference source but ran into problems. As per their suggestion for troubleshooting I tried to validate that I am using the right .NET framework version. ildasm however shows this:

enter image description here

I did however change the target framework of the project as you can see here:

enter image description here

Do I need to change the version somewhere else?

Sarien
  • 6,647
  • 6
  • 35
  • 55
  • Did you try rebuilding the project? –  Apr 03 '14 at 17:50
  • @LRNAB Yes, several times and I closed and re-opened Visual Studio, too. – Sarien Apr 03 '14 at 17:54
  • Are you thinking that `Metadata version` should be different for .Net framework 4.0 and 4.5 ? – Habib Apr 03 '14 at 17:54
  • I suspect it is just a version number issue. [This post](http://stackoverflow.com/a/12972517/1822514) indicates that the version numbers for the 4.5 framework still start with "4.0". – chue x Apr 03 '14 at 18:00
  • @Sarien Try using Telerik's [decompiler](http://www.telerik.com/products/decompiler.aspx) –  Apr 03 '14 at 18:02

2 Answers2

7

What you got is accurate. A project that targets .NET 4.5 or 4.5.1 still uses CLR version 4.0.30319 and core framework assemblies like mscorlib v4.0.0.0

This is largely a repeat with what happened for .NET versions 3.0, 3.5 and 3.5SP1, they target CLR version 2.0.50727 and core framework assemblies v2.0.0.0. Just like 4.5 and 4.5.1, they were not new side-by-side versions. They just added new assemblies to the existing set.

You can still tell what target you have selected with ildasm.exe, look at the System.Runtime.Versioning.TargetFrameworkAttribute attribute you see in the metadata. The CLR checks this to ensure you are not trying to run a 4.5.1 on a .NET 4.0 or 4.5 install. Offering to download the version you need. It looks like this (edited for readability):

 .custom instance void [mscorlib]System.Runtime.Versioning.TargetFrameworkAttribute::.ctor(string) = 
( 01 00 1C 2E 4E 45 54 46 72 61 6D 65 77 6F 72 6B   // ....NETFramework
  2C 56 65 72 73 69 6F 6E 3D 76 34 2E 35 2E 31 01   // ,Version=v4.5.1.
  00 54 0E 14 46 72 61 6D 65 77 6F 72 6B 44 69 73   // .T..FrameworkDis
  70 6C 61 79 4E 61 6D 65 14 2E 4E 45 54 20 46 72   // playName..NET Fr
  61 6D 65 77 6F 72 6B 20 34 2E 35 2E 31 )          // amework 4.5.1
Hans Passant
  • 922,412
  • 146
  • 1,693
  • 2,536
0

If you are trying to determine .Net framework version from Metadata version, then it is not the right way.

Metadata version shows the runtime version or CLR version.

the .NET Framework 4, 4.5, and 4.5.1 include CLR 4, but the .NET Framework 2.0, 3.0, and 3.5 include CLR 2.0. (There was no version 3 of the CLR.)

So for .Net framework 4, 4.5 and 4.5.1 you will see the same CLR version i.e. V4.0.30319. You may see this answer for identifying .Net framework version.

Community
  • 1
  • 1
Habib
  • 219,104
  • 29
  • 407
  • 436
  • This is a very good answer except for "it can safely be assumed". It should be verified. You are correct that the method outlined in the question fails to do so. – Ben Voigt Apr 03 '14 at 18:19
  • @BenVoigt, I am actually trying to find resource/reference for identifying the .Net framework version of an application. But you are right, I should modify that sentence – Habib Apr 03 '14 at 18:20