You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When serializing a covariant generic type (like ReadOnlyCollection<out T>), it is possible to serialize objects with the _type missing (which will cause deserialization to fail).
Here's a minimum repro:
usingLiteDB;usingSystem;usingSystem.Collections.Generic;usingSystem.Linq;usingSystem.Text;usingSystem.Threading.Tasks;usingXunit;namespaceLiteDB.Tests;publicclassLiteDB_Bug{[Fact]publicvoidCovariantCollectionIsMissingTypeInfo(){IAa=newA{Bs=newList<B>{newB()}};vardocA=BsonMapper.Global.Serialize<IA>(a).AsDocument;vardocB=docA["Bs"].AsArray[0].AsDocument;Assert.True(docA.ContainsKey("_type"));// OKAssert.True(docB.ContainsKey("_type"));// KO}interfaceIA{// at runtime this will be a List<B>IReadOnlyCollection<IB>Bs{get;set;}}classA:IA{publicIReadOnlyCollection<IB>Bs{get;set;}}interfaceIB{}classB:IB{}}
The issue seems to come from this line which uses obj.GetType() and pass down that type, when it should use type to extract the item type.
The text was updated successfully, but these errors were encountered:
When serializing a covariant generic type (like
ReadOnlyCollection<out T>
), it is possible to serialize objects with the _type missing (which will cause deserialization to fail).Here's a minimum repro:
The issue seems to come from this line which uses
obj.GetType()
and pass down that type, when it should usetype
to extract the item type.The text was updated successfully, but these errors were encountered: