asynkron / Wire

Binary serializer for POCO objects
Apache License 2.0
376 stars 63 forks source link

Serialization of F# Map #120

Closed xunilrj closed 7 years ago

xunilrj commented 8 years ago

Wire appears to have a problem to serialize a F# Record that contains a Map. For example:

F#

type RecordWithString = {Name:string}
type RecordWithMap = {SomeMap: Map<int,string>}
let createRecordWithMap = {SomeMap = Map.empty }

C#

var s = new Wire.Serializer();

var mem = new MemoryStream();
var r1 = new RecordWithString("somestring");
s.Serialize(r1, mem); //this works!

mem = new MemoryStream();
var r2 = SomeBank.Accounts.Domain.createRecordWithMap;
s.Serialize(r2, mem); //this throws the exception below

This is the exception message.

An exception of type 'System.Exception' occurred in Wire.dll but was not handled in user code
Additional information: Unable to write all fields of RecordWithMap
rogeralsing commented 8 years ago

I've added your code to the test suite. The issue is that the F# map is treated like a generic dictionary custom dictionary, which it is. That is, it implements IDictionary<TKey,TValue> but not IDictionary So far so good, the issue here is that the serializer factory for this case is not implemented, it throws in DictionarySerializerFactory.cs. (The built in standard .net dictionaries do support the IDictionary interface and are thus not affected)

I will get on this

rogeralsing commented 7 years ago

I have implemented the F# Map serializer: https://github.com/AsynkronIT/Wire/blob/dev/Wire/SerializerFactories/FSharpMapSerializerFactory.cs

Tests are passing

gokhan275 commented 3 years ago

gungafo49@gmail.com

gokhan275 commented 3 years ago

gungafo49@gmail.com