-
XmlSerializer
Good day,
I have a class "TridaData" I want to serialize.
Program I report an error on this line:
XmlSerializer^ s = gcnew XmlSerializer (array<TridaDat^>::typeid);
error:
+ NamespaceList 0x026f83c0 { _defaultCapacity= _items= _size= ...} System::Collections::ArrayList^
full program:
http://leteckaposta.cz/437977355
Thank you very much for the advice.
written in VS 2008, VC + +
-
Re: XmlSerializer
I don't believe you can use the XmlSerializer on an array of objects in the 2008 version of .Net. I tried your code in Visual Studio 2012 and it works fine.
As a work-a-round, you could create a containing class with a property that is an array. Then you serialize this class.
For example (C# notation)
Code:
[Serializable]
public class TridaDats
{
[XmlElement]
public TridaDat[] Entries { get; set; }
}
var xmlSerializer = new XmlSerializer(typeof(TridaDats));
...
-
Re: XmlSerializer
Program written in C # and it works to me.
This way I got it:
Code C#:
Code:
static public void SerializeToXML(TridaDat[] process, System.Windows.Forms.SaveFileDialog sfd)
{
XmlSerializer serializer = new XmlSerializer(typeof(TridaDat[]));
TextWriter textWriter = new StreamWriter(sfd.FileName);
serializer.Serialize(textWriter, process);
textWriter.Close();
}
I need to rewrite to VC+ +,to school.
-
Re: XmlSerializer
XML-serializing an array shouldn't be a problem. In fact I do that myself all the time. However, most of the more advanced collections can't be XML-serialized that easily. If I need to serialize one of those, I've made the habit to first convert them to an array and then serialize that. Advanced features like implicit sorting or keyed access don't really need to be serialized anyway in most cases and can be reconstructed upon deserialization. And even though it's a rather plain kind of a collection, AFAIR an ArrayList is one of those that can't be XML-serialized, and I think that's what the error message is trying to tell the OP. Unlike the error message, the original code snippet doesn't mention that collection type, but I suspect the array item type TridaDat contains a field of that type.