Serialize a class containing a list<float[]> using SOAP Edit: list<MyClass>
c#, linq, serialization, soap
Solution
I guess I will answer it since there are no takers. I found this while reading the forum linked above.
Just need to use an 'XmlSerializer' instead of a SOAP serializer. It works relatively the same. Now if I make a change to a class I don't have to change the Linq to XML code as well. Plus it is only a couple lines now.
Looks like they stopped supporting Soap and Soap doesn't support serializing generic lists.
public void saveXML(string filePath)
{
using (FileStream stream = new FileStream(filePath, FileMode.Create))
{
XmlSerializer format = new XmlSerializer(typeof(List<MyClass>));
format.Serialize(stream, this.postList);
}
}
private void readXML(string fileLocation)
{
using (FileStream stream = new FileStream(fileLocation,FileMode.Open))
{
XmlSerializer format = new XmlSerializer(typeof(List<MyClass>));
postList = format.Deserialize(stream) as List<MyClass>;
}
}
Reference
Problem
So I have a class that contains a list of floats[]. Everything except this field is serializable. The size of the list varies but the size of the float[] is constant. ``` List<float[]> listOfStuff; ``` I have written a method which uses Linq to XML to write the files but I'm hoping to use a Soap or Binary formatter to do the job. I'm thinking if I change the class I don't have to change all of the reading and writing methods and if need be I can serialize the files using a Binary formatter. Plus it is essentially a couple lines of code versus many. Any ideas on how to write a single file for an object containing a List using serialization? Edit: I'm getting the error: ``` An unhandled exception of type 'System.Runtime.Serialization.SerializationException' occurred in System.Runtime.Serialization.Formatters.Soap.dll Additional information: Soap Serializer does not support serializing Generic Types : System.Collections.Generic.List`1[Application.MyClass]. ``` Thanks BRAHIM Kamel The problem isn't the List in the object as Brahim said in the comments, that seems to work fine. It's the List of those objects that I'm having trouble writing to one file(so one level deeper). I tried to serialize the class that does the writing and contains the List I want to write, and got the above error.