vb.nettypesfully-qualified-naming

GetType from fully qualified type name not working


Public Sub New(ByVal oldC As Control)
    Dim FQTN As String = oldC.GetType.FullName
    Dim t As Type = Type.GetType(FQTN)
    Dim newC As Object = Activator.CreateInstance(t)
End Sub

FQTN is returning the correct Type name, but t is Nothing. For instance, FQTN = System.Windows.Forms.Panel.


Solution

  • Get rid of FQTN.

    This works with the panel example you're looking for

    Public Sub New(ByVal oldC As Control)
        Dim t As Type = oldC.GetType()
        Dim newC As Object = Activator.CreateInstance(t)
    End Sub
    

    Also, this is a duplicate of Type.GetType("namespace.a.b.ClassName") returns null