dahomey-technologies/Dahomey.Cbor

Empty arrays fail to serialize

Closed this issue · 4 comments

Serialization of empty (non-null) arrays throws an exception. CborWriter.WriteArray always tries to serialize at least one item even if the array is empty.

Just noticed this is fixed in #71. Release would be very much appreciated as this is a fairly common scenario.

#71 fix has been included in release 1.15.0

Are you sure the fix is included? I just tried it and I am getting the same exception:

Unhandled exception. System.IndexOutOfRangeException: Index was outside the bounds of the array.
   at Dahomey.Cbor.Serialization.Converters.ArrayConverter`1.WriteArrayItem(CborWriter& writer, WriterContext& context)
   at Dahomey.Cbor.Serialization.Converters.ArrayConverter`1.Write(CborWriter& writer, TI[] value, LengthMode lengthMode)
   at Dahomey.Cbor.Serialization.Converters.MemberConverter`2.Write(CborWriter& writer, Object obj)
   at Dahomey.Cbor.Serialization.Converters.ObjectConverter`1.WriteMapItem(CborWriter& writer, MapWriterContext& context)
   at Dahomey.Cbor.Serialization.Converters.ObjectConverter`1.Write(CborWriter& writer, T value, LengthMode lengthMode)
   ...

ArrayConverter.WriteArrayItem seems to have the same bug that #71 fixed in CborValueConverter.WriteArrayItem.