Skip to sidebar Skip to content
Ipercube Technical
Jack of all trades, master of none
Date: Time: - Stardate:
Welcome, Log in by clicking  Here!
SS64
MDN
Stack
Code
GitHub
Wiki
Convert
V Studio
  • Home
  • VB Functions
    • Access Functions
    • Assembly Info
    • Color/Image Functions
    • Data Table Functions
    • Email Functions
    • Active Directory Functions
    • LDAP Functions
    • Excel Functions
    • Logging Functions
    • Source Code Retrieval
    • String Functions
    • Sql Functions
    • Object Utilities Functions
    • System and Utilities
    • Utility Forms
  • VB Classes
    • Environment Variables Helper
  • ABAP
    • ABAP Reports
    • ABAP HTTP Functions
Ipercube Technical
  • Home
  • VB Functions
    • Access Functions
    • Assembly Info
    • Color/Image Functions
    • Data Table Functions
    • Email Functions
    • Active Directory Functions
    • LDAP Functions
    • Excel Functions
    • Logging Functions
    • Source Code Retrieval
    • String Functions
    • Sql Functions
    • Object Utilities Functions
    • System and Utilities
    • Utility Forms
  • VB Classes
    • Environment Variables Helper
  • ABAP
    • ABAP Reports
    • ABAP HTTP Functions

Get Framework Info

Retrieves the target .NET Framework version of a given assembly.

The function first attempts to read the TargetFrameworkAttribute to determine the framework. If the attribute is not present (e.g., in assemblies built before .NET 4.0), it falls back to inspecting the version of the referenced mscorlib.

VB
    Public Function GetFrameworkInfo(Assembly As Assembly) As String

        Dim frameWork As String = String.Empty

        'Try to get TargetFrameworkAttribute
        Dim attributes() As Object = Assembly.GetCustomAttributes(GetType(TargetFrameworkAttribute), False)
        If attributes.Length > 0 Then
            Dim tfa As TargetFrameworkAttribute = CType(attributes(0), TargetFrameworkAttribute)
            frameWork = tfa.FrameworkName
        Else
            'For assemblies compiled with versions previous .NET 4.0, analyse the referenced mscorlib
            Dim referencedAssemblies() As AssemblyName = Assembly.GetReferencedAssemblies()
            Dim mscorlibRef As AssemblyName = referencedAssemblies.FirstOrDefault(Function(a) a.Name = "mscorlib")
            If mscorlibRef IsNot Nothing Then
                frameWork = mscorlibRef.Version.ToString()
            End If
        End If

        Return frameWork.Replace(",", ", ").Replace("=v", " ").Replace(".NET", ".NET ")
    End Function

Posted by ipercube


© 2026 Ipercube Design