c# - Confirm or deny: The XmlSerializer cannot serialize the following: arrays of ArrayList and arrays of List -
the documentation xmlserializer.serialize method states following:
the
xmlserializer
cannot serialize following: arrays ofarraylist
, arrays oflist<t>
.
however if try following code works (i use list<int>
, arraylist
). documentation defect, new feature in .net 4.5 hasn't made it's way documentation?
i had suspected abbreviated message how cannot serialise list<t>
unless have all types in object graph, doesn't make sense arraylist object
.
private static string serialise<t>(t o) { var serializer = new xmlserializer(typeof(t)); var memorystream = new memorystream(); serializer.serialize(memorystream, o); memorystream.position = 0; using (var reader = new streamreader(memorystream)) { return reader.readtoend(); } }
read documentation again - says can't serialize arrays of list<t>
or arraylist
(i.e. list<t>[]
, arraylist[]
).
sure enough, these work:
serialise(new arraylist()); serialise(new list<int>());
these not:
serialise(new arraylist[]{}); serialise(new list<int>[]{});
the latter throw exception:
system.invalidoperationexception:
unable generate temporary class(result=1)
.
Comments
Post a Comment