[Mono-dev] Dictionary serialization between MS.NET and Mono

John Lenz jlenz2 at math.uiuc.edu
Wed Jan 20 17:01:31 EST 2010


I am using mono 2.6.1, and trying to use .NET remoting with binary 
serialization to talk between a mono client and a MS.NET server.  Almost 
everything works except transferring an empty 
System.Collections.Generic.Dictionary<> class.

If I create an empty Generic.Dictionary<> object in mono and try and 
deserailize it on MS.NET, I get the following exception.

System.Runtime.Serialization.SerializationException: The Keys for this 
dictionary are missing.

If I add a value to the dictionary so it is no longer empty, it 
deserializes correctly and everything works.  It is only with an empty 
dictionary I get the error.

Looking at mcs/class/corlib/System.Collections.Generic/Dictionary.cs, I 
see the following code in GetObjectData()

    KeyValuePair<TKey, TValue> [] data = null;
    if (count > 0) {
	data = new KeyValuePair<TKey,TValue> [count];
	CopyTo (data, 0);
    info.AddValue ("HashSize", table.Length);
    info.AddValue ("KeyValuePairs", data);

The attached patch fixes the problem.  It seems MS.NET always expects an 
array, even if the dictionary is empty.


-------------- next part --------------
A non-text attachment was scrubbed...
Name: mono-dict-fix.diff
Type: text/x-patch
Size: 622 bytes
Desc: not available
Url : http://lists.ximian.com/pipermail/mono-devel-list/attachments/20100120/3d02771f/attachment.bin 

More information about the Mono-devel-list mailing list