title: Unable to cast object of type 'System.Collections.Generic.List`1[' to type 'System.Collections.Generic.IEnumerable`1['
body: <p>The error I get at Runtime is</p>
  
  <pre class="lang-none prettyprint-override"><code>Unable to cast object of type
  'System.Collections.Generic.List`1[TCPClientClean.ChatClient+LogTime]'
  to type
  'System.Collections.Generic.IEnumerable`1[TCPClientClean.TimeLogLabel+LogTime]'.
  </code></pre>
  
  <p>I have a class that is used for logging an event and saving the time stamp.  I then want to save the list that is made in the <code>TimeLogLabel</code> class and then reload at start up. The saving to a text file is solved and works but I am not understanding how to get the saved list back into the <code>TimeLogLabel</code> class.</p>
  
  <pre><code>Option Strict On
  Imports System.Text
  Imports System.IO
  Imports System.Collections.Generic
  Public Class TimeLogLabel
  Inherits Label
  
  Private m_VaraibleToSet As Boolean
  &lt;System.ComponentModel.Category("Control")&gt; _
  Public Property VaraibleToSet() As Boolean
      Get
          Return m_VaraibleToSet
      End Get
      Set(ByVal value As Boolean)
          m_VaraibleToSet = value
      End Set
  End Property
  Private m_PrefixText As String = "Prefix Text"
  &lt;System.ComponentModel.Category("Control")&gt; _
  Public Property PrefixText() As String
      Get
          Return m_PrefixText
      End Get
      Set(ByVal value As String)
          m_PrefixText = value
      End Set
  End Property
  Public Class LogTime
      Private m_EventName As String
      Public Property EventName() As String
          Get
              Return m_EventName
          End Get
          Set(ByVal value As String)
              m_EventName = value
          End Set
      End Property
      Private m_StartT As String
      Public Property StartT() As String
          Get
              Return m_StartT
          End Get
          Set(ByVal value As String)
              m_StartT = value
          End Set
      End Property
      Private m_StopT As String
      Public Property StopT() As String
          Get
              Return m_StopT
          End Get
          Set(ByVal value As String)
              m_StopT = value
          End Set
      End Property
      Private m_TSpan As String
      Public Property TSpan() As String
          Get
              Return m_TSpan
          End Get
          Set(ByVal value As String)
              m_TSpan = value
          End Set
      End Property
      Public Sub New( _
    ByVal m_EventName As String, _
    ByVal m_StartT As String, _
    ByVal m_StopT As String, _
    ByVal m_TSpan As String)
          EventName = m_EventName
          StartT = m_StartT
          StopT = m_StopT
          TSpan = m_TSpan
      End Sub
  End Class
  
  
  Public TimeList As List(Of LogTime) = New List(Of LogTime)
  
      Public Sub StartTimer()
      If Ons = False Then
          Ons = True
          EventIdInt = EventIdInt + 1
          EventIdStg = ""
          If EventIdInt &lt;= 9 Then
              EventIdStg = "0" &amp; CStr(EventIdInt)
          ElseIf EventIdInt &gt;= 9 Then
              EventIdStg = CStr(EventIdInt)
          End If
          StartTime = Now
          TimeList.Add(New LogTime(PrefixText &amp; " " &amp; EventIdStg,     "StartTime " &amp; StartTime, "", ""))
          Timer.Enabled = True
          Timer.Start()
      End If
  End Sub
  
  Public Sub StopTimer()
      If Ons = True Then
          Ons = False
          EventIdInt = EventIdInt + 1
          EventIdStg = ""
          If EventIdInt &lt;= 9 Then
              EventIdStg = "0" &amp; CStr(EventIdInt)
          ElseIf EventIdInt &gt;= 9 Then
              EventIdStg = CStr(EventIdInt)
          End If
          StopTime = Now
          TimeList.Add(New LogTime(PrefixText &amp; " " &amp; EventIdStg, "", _           "Stop Time " &amp; StopTime, " Up Time " &amp; AccTimeStg))
          Timer.Enabled = False
          Timer.Stop()
      End If
  End Sub
  
  
  
  
  
  
  Imports System.IO
  Imports System.Text.RegularExpressions
  Imports System.Collections.Generic
  Imports System.Linq  
  Public Class ChatClient   ' Form that has "TimeLogLabel" on the form
  
  
  Public Class LogTime
      Private m_EventName As String
      Public Property EventName() As String
          Get
              Return m_EventName
          End Get
          Set(ByVal value As String)
              m_EventName = value
          End Set
      End Property
      Private m_StartT As String
      Public Property StartT() As String
          Get
              Return m_StartT
          End Get
          Set(ByVal value As String)
              m_StartT = value
          End Set
      End Property
      Private m_StopT As String
      Public Property StopT() As String
          Get
              Return m_StopT
          End Get
          Set(ByVal value As String)
              m_StopT = value
          End Set
      End Property
      Private m_TSpan As String
      Public Property TSpan() As String
          Get
              Return m_TSpan
          End Get
          Set(ByVal value As String)
              m_TSpan = value
          End Set
      End Property
      Public Sub New( _
    ByVal m_EventName As String, _
    ByVal m_StartT As String, _
    ByVal m_StopT As String, _
    ByVal m_TSpan As String)
          EventName = m_EventName
          StartT = m_StartT
          StopT = m_StopT
          TSpan = m_TSpan
      End Sub
  End Class
  
  Private Sub ChatClient_Load(ByVal sender As System.Object, ByVal e s    System.EventArgs) Handles MyBase.Load
  
  Dim TimeListSaved As List(Of LogTime) = New List(Of LogTime)
      ' Dim TimeListSaved As IEnumerable(Of LogTime) = New List(Of LogTime)
  
      Dim Sartuptime As DateTime = Now
      TimeListSaved.Add(New LogTime("Prefix&amp;EvebtId 01", "Start Time " &amp; UpStartTime, "Stop Time", "Up Time"))
  
  LAtSvrComm.TimeList.AddRange(TimeListSaved)
  ' this is where I get my error
      ' Unable to cast object of type 
      'System.Collections.Generic.List`1[TCPClientClean.ChatClient+LogTime]'
      'to type 
      'System.Collections.Generic.IEnumerable`1[TCPClientClean.TimeLogLabel+LogTime]'.
      End Sub
  
  Private Sub ChatClient_FormClosing(ByVal sender As System.Object, ByVal e As 
  
  System.Windows.Forms.FormClosingEventArgs) Handles MyBase.FormClosing
  
  
  Dim FILE_NAME As String = "C:\LogSave.txt"
      Dim objWriter As New System.IO.StreamWriter(FILE_NAME)
  
      For Each TimeLogLabel In LAtSvrComm.TimeList
          objWriter.WriteLine(TimeLogLabel.EventName &amp; " * " &amp;     TimeLogLabel.StartT &amp; " * " &amp; TimeLogLabel.StopT &amp; _
                              " * " &amp; TimeLogLabel.TSpan)
      Next TimeLogLabel
      objWriter.WriteLine("end of " &amp; LAtSvrComm.PrefixText)
      End Sub
  
  
  
      objWriter.Close()
  end sub
  </code></pre>