question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Cryptic error message for ID field problem

See original GitHub issue

I got the following error: “Object reference not set to an instance of an object” when bulk inserting objects.

It took some time to figure out, that the problem is that the Id field has only a getter, but no setter. Like:

public int Id { get; }

This fixed it:

public int Id { get; set; }

Would it be possible to display a user friendly error in this case? thx

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:6

github_iconTop GitHub Comments

1reaction
JensSchadroncommented, Aug 11, 2019

Hi @bolner, just wanted to let you know that it will be possible in a future release of v5. Functionality has been added in commit d65b888a69c6dd6112df1d6644f0fa080711229b (pushed about 20 mins ago) and will be available in the next release of v5.

Therefor, I’ll be closing the issue if you don’t mind. Feel free to re-open the issue if you feel like it’s still needed.

1reaction
bolnercommented, Aug 1, 2019

Hi, the following code reproduces it. When the setter is given, then LiteDB automatically puts an auto-increment ID into the Id field.

using System.Collections.Generic;
using LiteDB;

namespace IssueRepro {
    class Program {
        class MyClass {
            public int Id { get; }
            public int Code { get; set; }
            public double Parameter { get; set; }

            public MyClass() { }

            public MyClass(int code, double parameter) {
                this.Code = code;
                this.Parameter = parameter;
            }
        }

        static void Main() {
            using (var db = new LiteDatabase($"filename=db.bin; journal=false")) {
                var collection = db.GetCollection<MyClass>("classes");

                var list = new List<MyClass> {
                    new MyClass(123, 34.56),
                    new MyClass(234, 56.67)
                };

                collection.InsertBulk(list);
            }
        }
    }
}

This is the exact exception:

Unhandled Exception: System.NullReferenceException: Object reference not set to an instance of an object.
   at LiteDB.LiteCollection`1.GetBsonDocs(IEnumerable`1 documents)+MoveNext()
   at LiteDB.LinqExtensions.YieldBatchElements[T](IEnumerator`1 source, Int32 batchSize)+MoveNext()
   at LiteDB.LiteEngine.<>c__DisplayClass22_0.<Insert>b__0(CollectionPage col)
   at LiteDB.LiteEngine.Transaction[T](String collection, Boolean addIfNotExists, Func`2 action)
   at LiteDB.LiteEngine.InsertBulk(String collection, IEnumerable`1 docs, Int32 batchSize, BsonType autoId)
   at LiteDB.LiteCollection`1.InsertBulk(IEnumerable`1 docs, Int32 batchSize)
   at IssueRepro.Program.Main() in C:\projects\issue_repro\Program.cs:line 28
Read more comments on GitHub >

github_iconTop Results From Across the Web

Why am I receiving cryptic error messages when ...
My virtual connection runs a custom SQL query from Oracle. When I attempt to extract the data, I receive email notifications of failure...
Read more >
Cryptic error when defining a mutation without ...
In this case I've added the following mutation query to relay and I've received a cryptic error, I cannot find any reference to...
Read more >
Designing Better Error Messages UX
They provide a very general statement explaining that the input is wrong, with plenty of floral and cryptic words along with it.
Read more >
Builds fail with cryptic message - Developer Community
This error started occurring without me doing any changes to my project, and it persists for more than a week: ##[error]An error occurred...
Read more >
RocksDB cryptic error message
This is an assertion failure raised by RocksDB, and it intentionally terminates the execution of the program.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found