mbraceproject / FsPickler

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

Deserializing a map gives an empty map #15

Closed ovatsus closed 10 years ago

ovatsus commented 10 years ago

I have a Map<string, Record>, and serialize it using:

let fsp = FsPickler()
fsp.Serialize(stream, map)

I checked the file and it looks fine, but when I deserialize it again with fsp.Deserialize<_>(stream) I get an empty map

ovatsus commented 10 years ago

Repro here: https://github.com/ovatsus/HouseHunter2/tree/775f6ca23627c66f05b72b23f03fc5120e965c6b

eiriktsarpalis commented 10 years ago

Strange, I have unit tests set up for maps. Can you verify that the bug persists if you use the Pickle/UnPickle methods instead of Serialize/Deserialize?

ovatsus commented 10 years ago

Adding a CLIMutable attribute to the record solves the problem, but I though that was not required. Json.NET gives a cast error between FSharpList to ICollection without the attribute, but FsPickler jsut fails silently, I would prefer it to also crash

eiriktsarpalis commented 10 years ago

I am unable to reproduce this problem. I used your type definitions and serialized/deserialized a singleton map using the Mock entry. Could you possibly write a self-contained, bare-minimum script that reproduces the problem?

ovatsus commented 10 years ago
eiriktsarpalis commented 10 years ago

I'm still pretty convinced that the issue lies with your implementation. For example, I was able to verify that FsPickler works correctly in the following snippet:

https://gist.github.com/eiriktsarpalis/e477b8c9602769c34d0f

As you can see, I create a map using your crawler implementation, then successfully serialize and deserialize using the same workflow. A race condition, maybe?

ovatsus commented 10 years ago

Humm, It's possible, I'll close the issue then

ovatsus commented 10 years ago

Thanks

eiriktsarpalis commented 10 years ago

Let me know how it works out, a curious issue nonetheless.

ovatsus commented 10 years ago

Tried again, and it's working both with and without the CLIMutable, so I was doing something wrong before. In any case I'm keeping Json.Net, performance is not a problem, and json is easier to debug than a binary file

eiriktsarpalis commented 10 years ago

I agree, binary serialisers is probably not the best choice when persisting data.