c# - Serialize run-time created type -
i have created type system.reflection.emit
following msdn doc
i create type , instance code :
//following tutorial created method returns dynamic type type mydynamictype = createnewobject("mydynamictype", fields); var instance = activator.createinstance(mydynamictype);
now want seralize object xmlserializer
tried :
filestream fs = new filestream(@"c:\test\serializeddynamic.xml", filemode.create); xmlserializer xs = new xmlserializer(typeof(object)); xs.serialize(fs, instance);
but throws exception :
"the type mydynamictype not expected. use xmlinclude or soapinclude attribute specify types not known statically."
any ?
expanding on comment:
i think issue you're creating xmlserializer
typeof(object)
.
if use either of following should work:
xmlserializer xs = new xmlserializer(mydynamictype); xmlserializer xs = new xmlserializer(instance.gettype());
Comments
Post a Comment