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

Popular posts from this blog

java - UnknownEntityTypeException: Unable to locate persister (Hibernate 5.0) -

python - ValueError: empty vocabulary; perhaps the documents only contain stop words -

ubuntu - collect2: fatal error: ld terminated with signal 9 [Killed] -