title: Generic Collection of T sub not working
body: <p>I'm trying to teach myself generics and trying to create a generic list(of T).  T in this case would be an object class that I've defined.  Everything seems to be working fine until I try to set a property within the generic type.  </p>
  
  <p>I get "Object Reference not set to an instance of an object" at this line here.
  <code>tType.GetProperty(ColumnName).SetValue(ListItemObject, ConvertedValue, Nothing)</code></p>
  
  <p>This is the sub I am inheriting within my T object. So I would call it like this. T.GetCollectionFromDB(), and then it will set T(me) with the collection data.  I can't figure out why I am getting the object reference error.  Perhaps you experienced professionals can let me know why.  Thanks in advance.</p>
  
  <pre><code>    Public Overloads Sub GetCollectionFromDB(ByVal ID As Integer)
          Try
              Dim BaseObject As New Object
              Dim tType As Type = GetType(t)
              Dim ListCollection As New List(Of t)
              Dim ListItemObject As Object
              Dim BaseType As Type = MyBase.GetType()
              Dim TableName As String = String.Empty
              Dim SQL As New LottoPayload.DataHandler.SQLiDataClass
              Dim SQLString As String = String.Empty
              Dim SQLCommand As SQLiteCommand = Nothing
              Dim SQLConnection As SQLiteConnection = Nothing
              Dim SQLiteDRObj As SQLiteDataReader = Nothing
              Dim SQLResultsTable As New DataTable
  
              'Create an instance of the base object
              BaseObject = Activator.CreateInstance(BaseType)
              'Get the tablename from the object
              If Not BaseObject Is Nothing Then
                  TableName = BaseType.GetProperty("TableName").GetValue(BaseObject, Nothing).ToString
                  If Not TableName Is Nothing Then
                      SQLString = "SELECT * FROM " &amp; TableName &amp; " WHERE GameID = '" &amp; ID.ToString &amp; "'"
                      SQLConnection = SQL.GetSqlConnection()
  
                      SQLConnection.Open()
                      SQLCommand = New SQLiteCommand(SQLConnection)
                      SQLCommand.CommandText = SQLString
  
                      SQLiteDRObj = SQLCommand.ExecuteReader()
  
                      SQLResultsTable.Load(SQLiteDRObj)
                      If SQLResultsTable.Rows.Count &gt; 0 Then
                          For Each Row As DataRow In SQLResultsTable.Rows
                              'Create a new object
                              ListItemObject = Activator.CreateInstance(tType)
                              For Each Column As DataColumn In Row.Table.Columns
  
                                  Dim ColumnName As String = Column.ColumnName.ToString
                                  'Console.WriteLine(Row.Item(ColumnName))
                                  Dim ColumnValue As Object = Row.Item(ColumnName)
                                  'Console.WriteLine(Column.DataType.Name &amp; "    ")
                                  Select Case Column.DataType.Name
                                      Case "Int64"
                                          Dim ConvertedValue As Integer
                                          Integer.TryParse(ColumnValue.ToString, ConvertedValue)
                                          tType.GetProperty(ColumnName).SetValue(ListItemObject, ConvertedValue, Nothing)
                                      Case "Double"
                                          Dim ConvertedValue As Double
                                          Double.TryParse(ColumnValue.ToString, ConvertedValue)
                                          tType.GetProperty(ColumnName).SetValue(ListItemObject, ConvertedValue, Nothing)
                                      Case "String"
                                          Dim ConvertedValue As String
                                          ConvertedValue = ColumnValue.ToString
                                          tType.GetProperty(ColumnName).SetValue(ListItemObject, ConvertedValue, Nothing)
                                      Case Else
                                          Dim ConvertedValue As String
                                          ConvertedValue = "NotSet"
                                          tType.GetProperty(ColumnName).SetValue(ListItemObject, ConvertedValue, Nothing)
  
                                  End Select
  
                              Next
  
                              ListCollection.Add(DirectCast(ListItemObject, t))
                              ListItemObject = Nothing
                          Next
  
                      End If
  
  
                      SQLiteDRObj.Close()
                      SQLConnection.Close()
                      SQLConnection.Dispose()
                  End If
              End If
          Catch ex As Exception
              MessageBox.Show(ex.Message)
          Finally
  
          End Try
      End Sub
  </code></pre>