Https://gqqnbig.me/2015/11/23/net-framework%e7%89%88%e6%9c%ac4-0-30319-asp-net%e7%89%88%e6%9c%ac4-6-118-0/?utm _source=tuicool&utm_medium=referral
The. NET Framework 4.5 is an in-place upgrade that directly upgrades. NET 4.0 instead of co-existing with. NET 4.0. [1]
The. NET Framework 4.5 is composed of the common language runtime (CLR) 4.0, some new classes, and the old class's patches, so it Environment.Version
still returns 4.0.30319.42000.
When you install Visual Studio 2015,. NET 4.6 is also installed together, and 4.6 is also an in-place upgrade. [2]
In a project with a target version of 4.0, it is not common sense to access the classes and methods introduced by 4.6.
Ireadonlycollection<> generic interface is introduced in. NET 4.5, and of course not available in 4.0
But if you search for an assembly using reflection, you'll find that ireadonlycollection actually loaded in.
If you have. NET 4.5 installed, even a new type with the target version of 4.0,4.5 will be loaded in
In addition, upgrades of 4.5 and 4.6 include modifications to 4.0 types, such as the System.Web.UI.Control New Beginrendertracing () method.
Therefore, it is only a limitation that Visual Studio does not have access to the 4.5 type in a project with a target version of 4.0. That means your program is running in version 4.5, but you still cheat yourself that you're running 4.0.
So, if you've already upgraded to the. NET Framework 4.5 or 4.6, it is recommended to upgrade your 4.0 projects to the highest version at the same time, avoid fooling yourself, use more new types and methods, and troubleshoot problems and know that this is 4.5 or 4.6, not 4.0, unless you have a machine that does not upgrade 4.5.
The test code used in this article is as follows
[Code Lang= "VB"]
Private Sub default_load (sender as Object, e as EventArgs) Handles Me.load
Response.Write (". NET framework version is" & Environment.Version.ToString & ". <br/> ")
' Dim A as System.Collections.Generic.IReadOnlyCollection (of String)
Dim allloadedtypes = AppDomain.CurrentDomain.GetAssemblies (). SelectMany (Function (x) x.gettypes ())
Dim typeofireadonlycollection = Allloadedtypes.firstordefault (Function (x) x.name.contains ("Ireadonlycollection")
If typeofireadonlycollection IsNot Nothing Then
Response.Write ("Found Ireadonlycollection, it has" & Typeofireadonlycollection.getmethods (). Count & "Methods and" _
& Typeofireadonlycollection.getproperties (). Count & Properties. ")
End If
' For each type in Allloadedtypes
' Response.Write (type. AssemblyQualifiedName & "<br/>")
' Next
End Sub
[/code]
. NET Framework version: 4.0.30319; Asp. NET version: 4.6.118.0