After upgrading LiteDB to version 5.0.21 it stopped working correctly. The reason is that the constructor tagged with BsonCtorAttribute is not called. In version 5.0.17 it is correctly called. My class definition are as follows:
public abstract class DB_Object {
[Browsable(false)]
public abstract Guid Id { get; }
public abstract string Name { get; }
[Browsable(false)]
[BsonIgnore]
public virtual Bitmap Icon => null;
public override bool Equals(object? obj) {
var other = obj as DB_Object;
if (other == null) return false;
return Id.Equals(other.Id);
}
}
public class PlayList : DB_Object {
public PlayList(string name) {
PlayListId = Guid.NewGuid();
Name = name;
}
[BsonCtor]
public PlayList(Guid _id, string name) {
PlayListId = _id;
Name = name;
}
[Browsable(false)]
public Guid PlayListId { get; }
/// <summary>
/// Playlist name.
/// </summary>
public override string Name { get; } = "";
public string Comment { get; set; } = "";
/// <summary>
/// List of image ids referenced.
/// </summary>
public List<Guid> ImageIds { get; set; } = new List<Guid>();
/// <summary>
/// Image filenames.
/// </summary>
public override Guid Id => PlayListId;
}