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);
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);