Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] BsonCtor not called #2578

Open
ReidarMidtun opened this issue Jan 2, 2025 · 0 comments
Open

[BUG] BsonCtor not called #2578

ReidarMidtun opened this issue Jan 2, 2025 · 0 comments
Labels

Comments

@ReidarMidtun
Copy link

Version
5.0.21

Describe the bug
After upgrading from version 5.0.17 the constructor tagged with the BsonCtor Attribute is not called. On version 5.0.17 it worked correctly.

Code to Reproduce

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;
}

Expected behavior
The PlayList(Guid _id, string name) ctor should be called by LiteDB when executing the following:

        var col = DB.GetPlayListCollection(DB.DataBase);
        var all = col.FindAll();
        foreach (var pl in all) {
            if (col.FindById(pl.Id) == null) {  // Returns null since the ctor is not called to initialize the id field
                return;
            }
        }

Screenshots/Stacktrace

Additional context

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant