Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

serializing and arraylist

Status
Not open for further replies.

slatet

Programmer
Sep 11, 2003
116
US
We are trying XmlSerialization for the first time. We are trying to copy an array list out to an xml document but keep getting a cast error. We've tried .toarray with no luck and now are trying .copyto. Any help is appreciated.

We have an obj called node with contains an arraylist called LinkEntries that contains the object Link. We want to serialize all of the LinkEntries. Here is what we currently have:


XmlSerializer TempSerializer = new XmlSerializer(typeof(Link));
MemoryStream TempMemory = new MemoryStream();
TextWriter TempTextWriter = new StreamWriter( @"C:\\temp\\output.xml" );
StreamWriter TempStreamWriter = new StreamWriter(TempMemory);
UTF8Encoding Encoding = new UTF8Encoding();

Array tempArray = Array.CreateInstance( typeof(Link), node.LinkEntries.Count);
node.LinkEntries.CopyTo(tempArray);

//and this is where it gets the error
TempSerializer.Serialize(TempTextWriter, tempArray);

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top