title: Unable to cast object of type 'System.Collections.Generic.List`1
body: <p>I do not understand this reference to another type 'System.Collections.Generic.List`1[CES.Model.SearchResult]' and how to resolve this issue.</p>
  
  <pre><code>Unable to cast object of type 'System.Collections.Generic.List`1[CES.Model.SearchResult]' to type 'CES.Model.SearchResult'. 
  Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. 
  
  Exception Details: System.InvalidCastException: Unable to cast object of type 'System.Collections.Generic.List`1[CES.Model.SearchResult]' to type 'CES.Model.SearchResult'.
  
  Source Error: 
  
  
  Line 1069:            XmlSerializer xs = new XmlSerializer(typeof(SearchResult));
  Line 1070:            TextWriter textWriter = new StreamWriter(@"C:\temp\results.xml");
  Line 1071:            xs.Serialize(textWriter, results);
  Line 1072:            ViewState["eventList"] = textWriter.ToString();
  Line 1073:            textWriter.Close();
  </code></pre>
  
  <p>Here is the searchResult class and it's contained SearchResultAttribute class.</p>
  
  <pre><code>public class SearchResult
  {
      private List&lt;SearchResultAttribute&gt; _attributes = null;
      private List&lt;SearchResult&gt; _linkedSearchResults = null;
  
      public string this[string key]
      {
          get
          {
              int resultIndex = _attributes.BinarySearch(new SearchResultAttribute(key, ""));
  
              if (resultIndex &lt; 0)
                  return "";
              else
                  return _attributes[resultIndex].Value;
          }
          set
          {
              int resultIndex = _attributes.BinarySearch(new SearchResultAttribute(key, ""));
  
              if (resultIndex &lt; 0)
                  return;
              else
                  _attributes[resultIndex].Value = value;
          }
      }
  
      public List&lt;SearchResultAttribute&gt; Attributes
      {
          get
          {
              return _attributes;
          }
          set
          {
              _attributes = value;
          }
      }
      public List&lt;SearchResult&gt; LinkedSearchResults
      {
          get
          {
              return _linkedSearchResults;
          }
          set
          {
              _linkedSearchResults = value;
          }
      }
  
      public SearchResult()
      {
          _attributes = new List&lt;SearchResultAttribute&gt;();
          _linkedSearchResults = new List&lt;SearchResult&gt;();
      }
  }
  
  public class SearchResultAttribute:IComparer&lt;SearchResultAttribute&gt;,IComparable&lt;SearchResultAttribute&gt;
  {
      public string Key { get; set; }
      public string Value { get; set; }
  
      public SearchResultAttribute()
      {
          Key = System.String.Empty;
          Value = System.String.Empty;
      }
  
      public SearchResultAttribute(string key, string value)
      {
          Key = key;
          Value = value;
      }
  
      public int Compare(SearchResultAttribute x, SearchResultAttribute y)
      {
          return (x.Key.CompareTo(y.Key));
      }
  
      public int CompareTo(SearchResultAttribute other)
      {
          return this.Key.CompareTo(other.Key);
      }
  
  }
  </code></pre>
  
  <p>Thank you for your time.</p>