c# - XMLSerialization doesn't set properties on de-serialization -


i have weird behavior, don't know how diagnose.

some properties during de-serialization not set (null), though see them in (just-produced) xml document. xml document looks structured , symmetric regards similar types of objects.

it looks sets values point, stops setting values , beyond ignores other data.

just point out - last value sets correctly object of type contains object which, because of issues of singleton-like de-serialization, had implement ixmlserializable. i'm pointing out since hint @ bug, although can't figure out be.

edit: read some articles retrieving serialization assembly , code. reason, outputs .dll , .pdb file, not .cs, articles mention

thanks

ok, solved! two-part solution:

1) enabling diagnostics

first, in visual studio 2012 (or perhaps more correctly in .net 4.5), it's not enough set following in app.config xmlserialization diagnostic:

<system.diagnostics>     <switches>       <add name="xmlserialization.compilation" value="1" />     </switches> </system.diagnostics> <system.xml.serialization>     <xmlserializer tempfileslocation="c:\foo"/> </system.xml.serialization> 

you need add attribute uselegacyserializergeneration="true" produce auto-generated .cs file of serializer

<system.diagnostics>     <switches>       <add name="xmlserialization.compilation" value="1" />     </switches> </system.diagnostics> <system.xml.serialization>     <xmlserializer tempfileslocation="c:\foo" uselegacyserializergeneration="true"/> </system.xml.serialization> 

2) pitfall in ixmlserializable implementation

make sure xmlreader (when it's in readxml(xmlreader reader) method of ixmlserializable) on startelement of next element when you're done it, not on endelement. in other words, make sure call:

reader.readendelement(); 

because of it, xml deseralization reader got skewed data , read elements in wrong places, producing nulls.


Comments

Popular posts from this blog

How to mention the localhost in android -

php - Calling a template part from a post -

c# - String.format() DateTime With Arabic culture -