Unable to cast object of type 'System.Collections.Generic.List`1


I don't understand this reference to other type 'System.Collections.Generic.List`1CES.Model.SearchResult' and How can i resolve this problem.
incapable to cast object of type 'System.Collections.Generic.List`1CES.Model.SearchResult' to type 'CES.Model.SearchResult'. 
Description: An unhandled exception occurred during the execution of the current web request. Plz review the stack trace for more info about the error and where it originated in the code snippet.
Exception Details: System.InvalidCastException: incapable to cast object of type 'System.Collections.Generic.List`1CES.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 output);
Line 1072: ViewState"eventList" = textWriter.ToString();
Line 1073: textWriter.Close();

This is the searchResult class and it is contained SearchResultAttribute class.
public class SearchResult
{
private List _attributes = null;
private List _linkedSearchResults = null;
public string thisstring key
{
get
{
int resultIndex = _attributes.BinarySearch(new SearchResultAttribute(key ""));
if (resultIndex < 0)
return "";
else
return _attributesresultIndex.Value;
}
set
{
int resultIndex = _attributes.BinarySearch(new SearchResultAttribute(key ""));
if (resultIndex < 0)
return;
else
_attributesresultIndex.Value = value;
}
}
public List Attributes
{
get
{
return _attributes;
}
set
{
_attributes = value;
}
}
public List LinkedSearchResults
{
get
{
return _linkedSearchResults;
}
set
{
_linkedSearchResults = value;
}
}
public SearchResult()
{
_attributes = new List();
_linkedSearchResults = new List();
}
}
public class SearchResultAttribute:IComparer IComparable
{
public string Key { get; set; }
public string Value { get; set; }
public SearchResultAttribute()
{
Key = System.String.blank;
Value = System.String.blank;
}
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);
}
}

Thnk u for your time.



Get Source Code

  Views 502   Posted on : Thursday, March 21, 2013 10:41:50 AM
Related Tags:




Replies on "Unable to cast object of type 'System.Collections.Generic.List`1" :

Nobody has replied on this post , be first to post answer.


Post Your Answer/Comment:

Please Login first to post Reply !


Note: Please Put Code into <code></code> block.




Also See: