validation - An error when serializing a list of validationattribute -
i trying serialize list of (validationattribute) shown below:
requiredattribute trequired = new requiredattribute(); list<validationattribute> validationlist = new list<validationattribute>(); validationlist.add(trequired); xmlserializer txmlserializer = new xmlserializer(typeof(list<validationattribute>)); memorystream tmemstream = new memorystream(); streamwriter tstreamwriter = new streamwriter(tmemstream); txmlserializer.serialize(tstreamwriter, validationlist);
when (serialize) function execute, following exception thrown:
the type system.componentmodel.dataannotations.requiredattribute not expected. use xmlinclude or soapinclude attribute specify types not known statically
i have figured out. needed pass type of (requiredattribute) xmlserializer:
requiredattribute trequired = new requiredattribute(); list<validationattribute> validationlist = new list<validationattribute>(); validationlist.add(trequired); type[] textratypes = new type[] { typeof(requiredattribute) }; xmlserializer txmlserializer = new xmlserializer(typeof(list<validationattribute>),textratypes );
Comments
Post a Comment