Open roubachof opened 2 years ago
I have a similar issue. In my case, I am working in F# (.NET 6.0) and using v.5.0.11 of the library. I am using a record object. It seems to get added to the database collection, but finding it again produces the reported error.
@roubachof Try doing the little bit more verbose version with init
setters so that a default parameter-less constructor is created:
public record TourInfo()
{
public int Id { get; init; }
public Sector? Sector { get; init; }
public Collector Collector { get; init; }
public TourState TourState { get; init; }
public string? Name { get; init; }
public DateTime Date { get; init; }
public List<int> SortedCollectionIdList { get; init; }
}
See if that works for you. This still gives the benefit of the immutable structure but is a little longer.
hey @broknecho ! We changed our database since records and immutability is the base of our architecture, I'm afraid I won't be able to test this workaround (and I guess we wouldn't consider it acceptable :)
@roubachof But that's init-only setter, ie setters available only on costructor level - same code as yours, just with another syntax
Argh, I see - it does not require them to set, just alllow
I know it's only a syntax issue, but the construction declaration syntax is so much concise and readable I won't trade it vs something as verbose as init declaration, which is just, awful...
Issue seems to happen only with reference type positional parameters of a record type. Only workaround I found is refactor its to required init properties:
public record TourInfo(int Id, string Name)
{
public required Sector Sector { get; init; }
}
In my case it fails with the nullable values...
Version 5.0.11 / Xamarin.Forms Android
Describe the bug
LiteDB.LiteException: Failed to create instance for type 'CovaSud.TeamCollect.Domain.Tours.TourInfo' from assembly
Code to Reproduce
Try to serialize a simple Record object: