I am new to XmlSerializer. I wrote a small class for storing records from a database:
[Serializable] public struct Entry { public string artkey, lid, request, status, requestdate; }
Simple enough, right? It must be a piece of cake to serialize a list of them.
I have a function that compiles their list. To serialize my list, I try the following code:
XmlSerializer serializer = new XmlSerializer(typeof(Entry)); System.IO.MemoryStream ms = new System.IO.MemoryStream(); serializer.Serialize(ms, entries.ToArray()); ms.WriteTo(Response.OutputStream);
This code prints the following exception:
<error>System.InvalidOperationException: There was an error generating the XML document. ---> System.InvalidCastException: Specified cast is not valid. at Microsoft.Xml.Serialization.GeneratedAssembly.XmlSerializationWriterEntry.Write3_Entry(Object o) --- End of inner exception stack trace --- at System.Xml.Serialization.XmlSerializer.Serialize(XmlWriter xmlWriter, Object o, XmlSerializerNamespaces namespaces, String encodingStyle, String id) at System.Xml.Serialization.XmlSerializer.Serialize(Stream stream, Object o, XmlSerializerNamespaces namespaces) at System.Xml.Serialization.XmlSerializer.Serialize(Stream stream, Object o) at CCB_Requests.xmlResponse_selectFromCcb_Requests(HttpResponse response) at CCB_Requests.ProcessRequest(HttpContext context)</error>
It seems I should make a simple mistake. How can i fix this?
source share