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.

LiteDatabase.Shrink throws 'System.Collections.Generic.KeyNotFoundException'

See original GitHub issue

I get KeyNotFoundException upon any attempt to load/view database. Database file that raises KeyNotFoundException is generated by more than one process accessing one database, so this may be concurrency issue.

Snippet to reproduce:

using (var database = new LiteDatabase("sample.litedb"))
            {
                database.Shrink();
            }

or

            using (var database = new LiteDatabase("sample.litedb"))
            {
                database.Engine.FindAll(database.GetCollectionNames().FirstOrDefault()).ToArray();               
            }

etc.

Database file in question included: sample.zip

Please tell me what the possible cause is and how to avoid it in future.

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:18 (9 by maintainers)

github_iconTop GitHub Comments

1reaction
mbdavidcommented, Mar 9, 2018

Hi @Bounz, this bug was fixed but it’s not on nuget… I forgot about him… 😨 I will release new version this weekend.

0reactions
mbdavidcommented, Jun 27, 2018

Hi @md-zamolxis, I made a Recovery static method in LiteEngine to recovery datafile with link-pointer missing (like your example). It’s not 100% but works fine in my first example.

So, I recovery your data and works fine in master branch (with shrink too). You can get lastest version of LiteDB and run over your datafile to check. If you got any problem, please, open another issue about this.

Read more comments on GitHub >

github_iconTop Results From Across the Web

System.Collections.Generic.KeyNotFoundException upon ...
I'm building an contact manager application using .Net 5.0 in Visual Studio 2019 Community Edition. I am using MySql Connector (MySql.
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