mbraceproject / FsPickler

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

Serializing singletons using ISerializable/IObjectReference fails #44

Closed kevmal closed 9 years ago

kevmal commented 9 years ago

The exception message is "is ISerializable but does not implement constructor with parameters (SerializationInfo, StreamingContext)." But in the case of a singleton this is expected. SetType is used on SerializationInfo to set a IObjectReference helper type which contains the required constructor.

For example: https://msdn.microsoft.com/en-us/library/system.runtime.serialization.iobjectreference%28v=vs.110%29.aspx

eiriktsarpalis commented 9 years ago

Thanks,

I wasn't aware of this interface so I started reading through it. I found that it is being used in a variety of different ways, some of which seem a bit contradicting: for example

I need to figure out the canonical (i.e. most common) way this is being used.

eiriktsarpalis commented 9 years ago

This has been fixed as of FsPickler 1.0.19.

kevmal commented 9 years ago

Awesome. Did a quick test and seems to be working great. My use case was actually closer to the second link you posted, the MSDN page just seemed like the simplest example.