mbraceproject / FsPickler

A fast multi-format message serializer for .NET
http://mbraceproject.github.io/FsPickler/
MIT License
324 stars 52 forks source link

Deserializing boxed values #66

Closed liammclennan closed 8 years ago

liammclennan commented 8 years ago

My values are boxed before serializing to xml (for Sql xml type), which produces:

<FsPickler version="1.4.0.0" type="System.Object">
  <value flags="subtype">
    <subtype>
      <Case>NamedType</Case>
      <Name>Tests.WorkingWithDocuments+Person</Name>
      <Assembly>
        <Name>Tests</Name>
        <Version>0.0.0.0</Version>
        <Culture>neutral</Culture>
        <PublicKeyToken />
      </Assembly>
    </subtype>
    <instance>
      <id>71d5d868-cf28-404e-82c2-c7037e5b0c56</id>
      <age>45</age>
      <name>Cecile</name>
    </instance>
  </value>
</FsPickler>

This then fails to deserialize with:

Nessos.FsPickler.FsPicklerException : Error deserializing object of type 'Tests.WorkingWithDocuments+Person'.
---- Nessos.FsPickler.InvalidPickleTypeException : Expected pickle of type 'Tests.WorkingWithDocuments+Person' but was 'System.Object'.

Is there a way to make it work?

eiriktsarpalis commented 8 years ago

Yes, just deserialize using object as your type parameter. In general, the serialized type should match the deserialized type. If unsure what type you are deserializing, just use object in all your serialization and deserialization invocations.

liammclennan commented 8 years ago

That works. Thank you.