GroBuf icon indicating copy to clipboard operation
GroBuf copied to clipboard

ValueTuple is not supported as dictionary key when using AllPropertiesExtractor

Open AndrewKostousov opened this issue 5 years ago • 0 comments

The following code:

var serializer = new Serializer(new AllPropertiesExtractor());
var dict = new Dictionary<(string, string), string>
    {
        {("k11", "k12"), "v1"},
        {("k21", "k22"), "v2"}
    };
var bytes = serializer.Serialize(dict);
serializer.Deserialize<Dictionary<(string, string), string>>(bytes);

fails with:

System.ArgumentException : An item with the same key has already been added.
   at System.ThrowHelper.ThrowArgumentException(ExceptionResource resource)
   at System.Collections.Generic.Dictionary`2.Insert(TKey key, TValue value, Boolean add)
   at Read_Dictionary`2_7baa8df0-d792-4e03-bc5a-1291b06478b5(IntPtr , Int32& , Dictionary`2& , ReaderContext )
   at 7884d4f6-1cd8-4766-9648-ca5616cb25c2(IntPtr , Int32& , Dictionary`2& , ReaderContext )
   at GroBuf.GroBufReader.Read[T](IntPtr data, Int32& index, Int32 length, T& result) in C:\projects\open-source\skbkontur\GroBuf\GroBuf\GroBufReader.cs:line 98
   at GroBuf.GroBufReader.Read[T](Byte[] data, T& result) in C:\projects\open-source\skbkontur\GroBuf\GroBuf\GroBufReader.cs:line 45
   at GroBuf.GroBufReader.Read[T](Byte[] data) in C:\projects\open-source\skbkontur\GroBuf\GroBuf\GroBufReader.cs:line 75
   at GroBuf.Serializer.Deserialize[T](Byte[] data) in C:\projects\open-source\skbkontur\GroBuf\GroBuf\Serializer.cs:line 50

serializer = new Serializer(new AllFieldsExtractor()) works as expected though.

AndrewKostousov avatar Apr 15 '19 05:04 AndrewKostousov